Created
March 7, 2018 20:22
-
-
Save robodellaz/364cd54149d51565a1bc20dc111ac6ff to your computer and use it in GitHub Desktop.
Congress API Jeff Flake
This file contains hidden or 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
import json | |
import csv | |
import requests | |
headers = {'X-API-Key': 'DzoRodfNtDdLcIOVzLWcaApiRvDTzXR48CPPyc93'} | |
offset=0 | |
for item in range(0, 1520): | |
url='https://api.propublica.org/congress/v2/members/F000444/votes.json?offset={0}'.format(offset) | |
req = requests.get(url, headers=headers) | |
data = req.json() | |
results = data['results'] | |
# change code to the location on your computer | |
with open('../json35/FlakeVotes.csv', 'a', newline="") as o: | |
writer = csv.writer(o) | |
writer.writerow([ | |
'member_id', | |
'chamber', | |
'congress', | |
'session', | |
'roll_call_votes', | |
'bill_id', | |
'title', | |
'latest_action', | |
'description', | |
'question', | |
'result', | |
'date', | |
'time', | |
'member_position', | |
'yes_votes', | |
'no_votes', | |
'present_votes', | |
'not_voting' | |
]) | |
for result in results: | |
member_id = result['member_id'] | |
votes = result['votes'] | |
for votes in votes: | |
chamber = votes['chamber'] | |
congress = votes['congress'] | |
session = votes['session'] | |
roll_call_votes = votes['roll_call'] | |
bill_id = votes['bill'].get('bill_id') | |
title = votes['bill'].get('title') | |
latest_action = votes['bill'].get('latest_action') | |
description = votes['description'] | |
question = votes['question'] | |
result = votes['result'] | |
date = votes['date'] | |
time = votes['time'] | |
yes_votes = votes['total'].get('yes') | |
no_votes = votes['total'].get('no') | |
present_votes = votes['total'].get('present') | |
not_voting = votes['total'].get('not_voting') | |
member_position = votes['position'] | |
writer.writerow([member_id, chamber, congress, session, roll_call_votes, bill_id, title, latest_action, description, question, | |
result, date, time, member_position, yes_votes, no_votes, present_votes, not_voting]) | |
offset+=20 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment