-
Notifications
You must be signed in to change notification settings - Fork 0
/
housescores.py
executable file
·58 lines (40 loc) · 1.5 KB
/
housescores.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import csv
from sunlight import openstates
ok_legislators = openstates.legislators(
state='ok',
active='true',
chamber='lower'
)
ok_legislators_csv_key = ['leg_id']
ok_legislators_array = []
for legislator in ok_legislators:
ok_legislators_csv_key.append(legislator['leg_id'])
ok_legislators_array.append(legislator['leg_id'])
with open('scores.csv', 'w') as w:
writer = csv.DictWriter(w, fieldnames=ok_legislators_csv_key, extrasaction='ignore')
writer.writeheader()
for legislatorA in ok_legislators_array:
print "Going through " + legislatorA
leg_scores = {}
leg_scores['leg_id'] = legislatorA
for legislatorB in ok_legislators_array:
# open the votes csv file
with open('housevotes.csv') as f:
reader = csv.DictReader(f)
voteCount = 0
voteSame = 0
notComparable = 0
for bill in reader:
if not bill[legislatorA] or not bill[legislatorB]:
notComparable += 1
elif bill[legislatorA] == bill[legislatorB]:
voteCount += 1
voteSame += 1
else:
voteCount += 1
try:
score = voteSame
leg_scores[legislatorB] = score
except ZeroDivisionError:
leg_scores[legislatorB] = "x"
writer.writerow(leg_scores)