-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcompare.py
executable file
·181 lines (161 loc) · 5.47 KB
/
compare.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/python
import os
#import socrata_rows as soc
import Current_members_of_the_United_States_House_of_Representatives as reps
import Ballotpedia_house as breps
import List_of_current_United_States_Senators as sens
import Ballotpedia_senator as bsens
import cache
import legislators_current as leg
from cStringIO import StringIO
rep= cache.cache('reps',reps.parse_rep)
brep= cache.cache('breps',breps.parse)
sen= cache.cache('sen',sens.parse)
bsen= cache.cache('bsen',bsens.parse)
congress = { 'wp' : rep['wp'].copy() }
congress['wp'].update(sen['wp'])
legs= leg.load()
def check(aobj,bobj,name):
if name in bobj['id'] :
bval= str(bobj['id'][name])
if name in aobj['links'] :
aval = str(aobj['links'][name])
if aval != bval :
print "Found " , name, aval, "/", bval
else:
pass
else:
if name in aobj['links'] :
val = str(aobj['links'][name])
print 'in b no ' + name , "IN A: ", name + ": " + val, bobj['id']
bobj['id'][name]=val
else:
pass
def check_basic(aobj,bobj,name):
if name in bobj['id'] :
bval= str(bobj['id'][name])
if name in aobj['links'] :
aval = str(aobj['links'][name])
if aval != bval :
print "Found " , name, aval, "/", bval
else:
pass
else:
if name in aobj['links'] :
val = str(aobj['links'][name])
print 'in b no ' + name , "IN A: ", name + ": " + val, bobj['id']
bobj['id'][name]=val
else:
print "missing ", name, bobj
pass
def check_basic_list(aobj,bobj,name):
if name in bobj['id'] :
bvals= bobj['id'][name]
match = 0
for bval in bvals :
if name in aobj['links'] :
aval = str(aobj['links'][name])
if aval == bval :
match = match +1
# if match
else:
if name in aobj['links'] :
val = str(aobj['links'][name])
print 'in b no ' + name , "IN A: ", name + ": " + val, bobj['id']
bobj['id'][name]=val
else:
print "missing ", name, bobj
pass
def check_cspan(aobj,bobj):
name='cspan'
if name in bobj['id'] :
bval= str(bobj['id'][name])
if name in aobj['links'] :
aval = str(aobj['links'][name])
if aval != bval :
# print "Found2 " , name, ":", aval, "/", bval, aobj
# aobj['links'][name]=bval
pass
else:
pass
else:
if name in aobj['links'] :
val = str(aobj['links'][name])
print "no cspan in yaml but in source: ", name + ": " , val, aobj
else:
pass
def compare(a,b) :
for x in sorted(a['wp'].keys()):
aobj = a['wp'][x]
if x in b['wp'] :
bobj = b['wp'][x]
if 'links' in aobj :
check(aobj,bobj,'bioguide')
check(aobj,bobj,'votesmart')
check_basic(aobj,bobj,'bioguide')
check_basic(aobj,bobj,'thomas')
# check_basic(aobj,bobj,'lis')
check_basic_list(aobj,bobj,'fec')
check_basic(aobj,bobj,'govtrack')
# check_basic(aobj,bobj,'icpsr')
# checkbasic(aobj,bobj,'house_history')
check_cspan(aobj,bobj)
# a['wp'][x]=
# print a['wp'][x]['cspan']
# check(aobj,bobj,'ballot')
else:
print 'no links'
print aobj
else:
print "missing ",name,"in b"
def compare_bpr(a,b) :
for x in sorted(a['wp'].keys()):
aobj = a['wp'][x]
# print aobj
if 'wikipedia' not in aobj['links']:
# print "Missing wikipedia in BP %s " % x, aobj
pass
else:
wp = aobj['links']['wikipedia']
if wp in b['wp'] :
bobj = b['wp'][wp]
if 'links' in aobj :
if 'ballot' in bobj['links']:
ballot = bobj['links']['ballot']
else:
#print 'no BP in wikipedia article ' , wp, bobj
# now we save the new ballotpedia link that we inferred
b['wp'][wp]['links']['ballot']=x
else:
print 'no links'
print aobj
else:
#print "Missing %s in wikipedia, wrong link" % x, aobj
pass
def compare_bpr_name(a,b,name) :
for x in sorted(a['wp'].keys()):
aobj = a['wp'][x]
if 'wikipedia' not in aobj['links']:
pass
else:
wp = aobj['links']['wikipedia']
if wp in b['wp'] :
bobj = b['wp'][wp]
if 'links' in aobj :
if name in bobj['links']:
ballot = bobj['links'][name]
else:
b['wp'][wp]['links'][name]=x
else:
print 'no links'
print aobj
else:
pass
compare_bpr(brep,rep)
compare_bpr(bsen,sen)
compare_bpr_name(brep,rep,'cspan')
compare_bpr_name(bsen,sen,'cspan')
compare(congress,legs)
import dump
leg.apply(legs)
dump.dump(legs)