-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsunlight.py
More file actions
25 lines (20 loc) · 892 Bytes
/
sunlight.py
File metadata and controls
25 lines (20 loc) · 892 Bytes
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
import requests
import json
apikey = "cf5e2bc757104bddb2063ac07e7499db"
request_str = "http://congress.api.sunlightfoundation.com/legislators?per_page=all&apikey=" + apikey
r = requests.get(request_str)
content = json.loads(r.text)
with open('accounts.tsv','w') as outfile:
for person in content['results']:
lastname = unicode(person['last_name'])
firstname = unicode(person['first_name'])
state_name = unicode(person['state_name'])
state_short = unicode(person['state'])
chamber = unicode(person['chamber'])
gender = unicode(person['gender'])
party = unicode(person['party'])
twitter_id = person[u'twitter_id'] if 'twitter_id' in person else None
# skip line if no twitter account
if not twitter_id: continue
line = firstname + " " + lastname + "\t" + state_short + "\t" + chamber + "\t" + party + "\t" + twitter_id
outfile.write(line.encode("utf8") + "\n")