Created
November 3, 2014 08:26
-
-
Save daonb/8ea262f90bc303f293d3 to your computer and use it in GitHub Desktop.
getting some votes in one csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
to make this work you need to have Open-Knesset source and latest db file | |
from the shell type:: | |
$ python manage.py shell_plus | |
In [1]: ed tomer.py | |
''' | |
import json, urllib2 | |
votes=[6904,7454,6786] | |
mk_votes= {} | |
for i in votes: | |
v=urllib2.urlopen("http://oknesset.org/api/v2/vote/{}/?format=json".format(i)).read() | |
v=json.loads(v) | |
print v | |
for j in v['votes']: | |
m=int(j['member'].split('/')[4]) | |
if m in mk_votes: | |
mk_votes[m][i] = j['vote_type'] | |
else: | |
mk_votes[m]={i: j['vote_type']} | |
f=open("tomer_votes.csv","w") | |
f.write('name,') | |
f.write(",".join([str(s) for s in votes])+'\n') | |
for mk, v in mk_votes.items(): | |
f.write('{},'.format(Member.objects.get(id=mk).name.encode('utf8'))) | |
for j in votes: | |
if j in v: | |
f.write(v[j]+',') | |
else: | |
f.write('not present,') | |
f.write('\n') | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment