In [37]:
    
import os
import sys
    
In [38]:
    
from importlib import reload
    
In [2]:
    
import pandas
    
In [3]:
    
sys.path.append(os.path.join(os.path.abspath('../..'), 'src'))
    
In [4]:
    
import utils
    
In [7]:
    
import init_NCCampaignDocument_table
    
In [53]:
    
reload(init_NCCampaignDocument_table)
    
    Out[53]:
In [88]:
    
enum_options = '24-Hour Electioneering Communications','48-Hour','Annual','Audit Letter','Campaign Reporter','Candidate Designation of Committee Funds','Candidate Specific Communications','Certification of Inactive Status','Certification of Incorporated Political Committee','Certification of Return to Active Status','Certification of Threshold','Certification of Treasurer','Certification to Close Committee','Contribution from a Business Account Statement','Correspondence Returned Undeliverable or Unclaimed','Declaration of Intent','Deferred Notice','District Attorney Letter','Electioneering Communications Report','Federal Mid Year','Federal Year End','Final','First Quarter','Forgiven Loan Statement','Fourth Quarter','Independent Expenditure Political Committee Certification','Independent Expenditure Report','Independent Expenditure for Registered Committees','Independent Expenditure for non-Committees','Interim','Judicial Qualifying Contributions Report','Loan Proceeds Statement','Mid Year Semi-Annual','Miscellaneous Correspondence','Monthly','Municipal Voter-Owned Election Qualifying Contributions','Non-Compliance Letter','Non-Participating Candidate','Notice of Candidacy','Notice of Termination of Active Status','Notification of Change to Reporting Schedule','Organizational','Other','Paid Penalty Assessment or Forfeiture','Penalty Appeal','Penalty Appeal Decision','Penalty Assessment','Penalty Assessment Letter','Penalty Resolution Agreement Executed','Penalty Resolution Agreement Proposal','Penalty Waiver Letter','Political Party Executive Committee Exempt Sales Plan','Post General','Post Primary','Pre-Election','Pre-Primary','Pre-Referendum','Pre-Runoff','Rescind Letter','Second Quarter','Signed Penalty Waiver Agreement','Special','Statement of Organization','Supplemental Final','Ten-day','Third Quarter','Thirty-day','Thirty-five-day','Twelve-day','Voter-Owned Election Qualifying Contributions','Weekly','Year End Semi-Annual'
enum_options = set(enum_options)
    
In [89]:
    
list(enum_options)[:3]
    
    Out[89]:
In [70]:
    
df = init_NCCampaignDocument_table.load_all()
    
In [86]:
    
df.shape
    
    Out[86]:
In [87]:
    
df.head()
    
    Out[87]:
In [90]:
    
def test_member(rt):
    if not rt:
        return(0)
    else:
        if rt in enum_options:
            return(0)
        else:
            return(1)
nienum = df.report_type.apply(test_member)
    
In [93]:
    
import numpy
    
In [100]:
    
for ind in numpy.where(nienum)[0]:
    print(df.report_type[ind])
    
    
In [65]:
    
keep = []
count = 0
for tup in df2014.itertuples():
    keep.append(list(tup)[1:])
    count += 1
    if count > 5000:
        break
    
In [66]:
    
keep[0]
    
    Out[66]:
In [67]:
    
keep = [{col:entry for col,entry in zip(df2014.columns, col)} for col in keep]
keep[0]
    
    Out[67]:
In [14]:
    
import mysql_utils
    
In [182]:
    
reload(mysql_utils)
    
    Out[182]:
In [21]:
    
add_entry = ("INSERT INTO " + 'camp_doc_lu' + " "
                 "(committee, report_year, report_type, amend, rec_date, start_date, end_date, image_link, data_link) "
                 "VALUES (%(committee)s, %(report_year)s, %(report_type)s, "
                 "%(amend)s, %(rec_date)s, %(start_date)s, %(end_date)s, "
                 "%(image_link)s, %(data_link)s)")
    
In [22]:
    
add_entry
    
    Out[22]:
In [68]:
    
with mysql_utils.curInsert() as cursor:
    for i,entry in enumerate(keep):
        cursor.execute(add_entry, entry)
    
In [69]:
    
i
    
    Out[69]:
In [52]:
    
keep[13]
    
    Out[52]:
In [ ]: