In [3]:
import sqlite3, os, urllib, zipfile
Download the data from the NC State Board of Elections. There used to be an actual, clean FTP site for downloading the data, but some time in 2016 the BOE opted to move everything to Amazon S3 and gave it a fake FTP-like interface for browsing election data. Kind of annoying, but, it could be worse.
The action voter database along with voter history lives in the /data/ directory. You can download the data for the entire state, but for sanity purposes, if you don't need the entire state, I recommend just grabbing the county data that you need. That's how this notebook is initially set up. County data is listed numerically by the number that a county appears in if arranged alphabetically. Go figure. Since that's pretty cryptic, I recommend reading the data format description file, which will also help you figure out what each of the columns represents.
In [4]:
directory = "datadir"
ncboeDir = "https://s3.amazonaws.com/dl.ncsbe.gov/data/ncvoter68.zip"
if not os.path.exists(directory):
os.makedirs(directory)
os.chdir(directory)
urllib.urlretrieve(ncboeDir, 'ncvoter68.zip')
In [5]:
zip_ref = zipfile.ZipFile('ncvoter68.zip', 'r')
zip_ref.extractall()
zip_ref.close()
In [ ]: