Skip to content

Instantly share code, notes, and snippets.

@fmasanori
Last active February 2, 2020 05:59
Show Gist options
  • Save fmasanori/b7b56cf9fb0a4a4e4a17 to your computer and use it in GitHub Desktop.
Save fmasanori/b7b56cf9fb0a4a4e4a17 to your computer and use it in GitHub Desktop.
propublica.py
from urllib.request import Request, urlopen
import json
url = "https://api.propublica.org/campaign-finance/v1/2016/president/totals.json"
q = Request(url)
q.add_header('X-API-Key', 'n8QLPm4lNS2Mfak1bam5X7HlevBAOSoF9epQkX0m')
data = urlopen(q).read()
data = json.loads(data.decode('utf-8'))
for candidate in data['results']:
print (candidate['name'])
print (candidate['total_contributions'])
print (candidate['cash_on_hand'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment