# Connect to the database conn = sqlite3.connect(prelimDB) cur = conn.cursor() # get the list of fields from the database cur.execute("PRAGMA table_info('libertarians')") pragma = cur.fetchall() # extract db field names from dbfields = [str(x[1]) for x in pragma] # Find some variables we'll need later PARTY_AFFILIATION = MyFunctions.first_startswith('PARTY_AFFILIATION',dbfields) LAST_PRIMARY_FIELD = MyFunctions.last_startswith('PRIMARY',dbfields) CONGRESSIONAL_DISTRICT = MyFunctions.last_startswith('CONGRESSIONAL_DISTRICT',dbfields) LAST_NAME = MyFunctions.first_startswith('LAST_NAME',dbfields) FIRST_NAME = MyFunctions.first_startswith('FIRST_NAME',dbfields) fieldsInLine = len(dbfields) # find the county data files, put them in an array & sort them. csvfiles = glob.glob('../ZIP/*.zip') csvfiles.sort() # parse the datafiles for onefile in csvfiles: countyCount = 1 # Set up variables needed later numVotersParsed = 0
# Connect to the database conn = sqlite3.connect(newDB) cur = conn.cursor() # get the list of fields from the database cur.execute("PRAGMA table_info('libertarians')") pragma = cur.fetchall() # extract db field names from dbfields = [str(x[1]) for x in pragma] # Find some variables we'll need later PARTY_AFFILIATION = MyFunctions.first_startswith('PARTY_AFFILIATION',dbfields) LAST_PRIMARY_FIELD = MyFunctions.last_startswith('PRIMARY',dbfields) LAST_NAME = MyFunctions.first_startswith('LAST_NAME',dbfields) FIRST_NAME = MyFunctions.first_startswith('FIRST_NAME',dbfields) fieldsInLine = len(dbfields) # find the county data files, put them in an array & sort them. csvfiles = glob.glob('../ZIP/*.zip') csvfiles.sort() # parse the datafiles for onefile in csvfiles: countyCount = 1 try: zf = zipfile.ZipFile(onefile, 'r') except zipfile.BadZipfile: