prelimDB = filePath+filePrefix+fileSuffix

# 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
    for error in errors:
        print error
    if not MyFunctions.query_yes_no("Proceed?"):
        print "Aborting..."
        sys.exit(65)
    else:
        if MyFunctions.query_yes_no("Rename files to exclude from processing?"):
            for error in errors:
                print "Renaming " + zipDirectory + error + " to: " \
                    + zipDirectory + error + ".ERROR"
                os.rename(zipDirectory + error, zipDirectory + error + ".ERROR")
else:
    print "\nAll files have identical fields!"
    print "All files have " + str(len(fields)) + " fields.\n"

firstElectionField = MyFunctions.first_startswith(('PRIMARY', 'GENERAL', 'SPECIAL'), fields)

# does the database even exist?

# open the database file
db = sqlite3.connect(databaseDirectory + 'Libertarians.db')
cur = db.cursor()

cur.execute("PRAGMA table_info('libertarians')")
pragma = cur.fetchall()
# extract db field names from
dbfields = [str(x[1]) for x in pragma]

if dbfields == fields:
    print "DB matches file format"
else:
    conn = sqlite3.connect(prelimDB)
    cur = conn.cursor()
else:
    print "Preliminary Database File " + prelimDB + " Does Not Exist"
    sys.exit()


# 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)
FIRST_PRIMARY_FIELD = MyFunctions.first_startswith('PRIMARY', 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)
ZIP = MyFunctions.first_startswith('RESIDENTIAL_ZIP', 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:
    countyAffiliations = {}