-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdouglas.py
42 lines (38 loc) · 1.4 KB
/
douglas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import csv
source = '/Users/derekwillis/Downloads/2018 Douglas County, CO precinct-level election results.txt'
offices = ['Representative to the 116th US Congress', 'Governor', 'Secretary of State', 'State Treasurer', 'Attorney General', 'State Representative']
lines = open(source).readlines()
results = []
for line in lines:
if line == '\n':
continue
if "ScanStations" in line:
continue
if "Cumulative" in line:
continue
if "General 2018" in line:
continue
if "Official Results" in line:
continue
if line[0:4] == 'Total':
continue
if "Vote %" in line:
continue
if "VOTES PERCENT" in line:
continue
if any(o in line for o in offices):
office = line.split('(Vote for 1)', 1)[0]
if "Precinct" in line:
precinct = line.strip()
if "%" in line:
# this is a result line
candidate, party = line.split(' ', 3)[2].split(').')[0].split(' (')
party = None
candidate = candidate.strip()
votes = line.split(' ', 3)[3].split(' ')[0].strip()
results.append(['Beaver', precinct, office, None, party, candidate, votes])
with open('20181106__pa__general__beaver__precinct.csv', 'wt') as csvfile:
w = csv.writer(csvfile)
headers = ['county', 'precinct', 'office', 'district', 'party', 'candidate', 'votes']
w.writerow(headers)
w.writerows(results)