Last active
December 14, 2015 07:29
-
-
Save rohinip/5051370 to your computer and use it in GitHub Desktop.
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
############################################################################# | |
# Documentation for python-sunlight: | |
# http://python-sunlight.readthedocs.org/en/latest/ | |
# | |
# Command line to install python-sunlight: | |
# (Note need 'sudo' because that lets you run as admin to do install!) | |
# sudo pip install sunlight | |
# | |
# Command Line: python SunlightFoundation.py | |
############################################################################# | |
# Import libraries | |
import sys | |
import os | |
import json | |
import math | |
import simplejson | |
import sunlight | |
from sunlight import congress | |
import requests | |
import pprint | |
# Global variables | |
sunlight.config.API_KEY = # Enter your API key here | |
# Search for who says annoying phrases the most | |
print "Enter a Washington jargon phrase and I'll tell you the top ten legislators who say it the most:" | |
jargon = raw_input() | |
searchRequest = 'http://capitolwords.org/api/1/phrases/legislator.json?phrase=%(phrase)s&sort=count&per_page=10&apikey=%(key)s' % {'phrase' : jargon, 'key' : sunlight.config.API_KEY} | |
topJargoners = requests.get(searchRequest) | |
jsonResponseJargoners = json.loads(topJargoners.text) | |
# Loop through the BIO_IDs and print out these top ten REAL_NAMES | |
for results in listOfResults: | |
bioKey = results[u'legislator'] | |
lookupRequest = 'http://congress.api.sunlightfoundation.com/legislators?bioguide_id=%(bioID)s&apikey=%(key)s' % {'bioID' : bioKey, 'key' : sunlight.config.API_KEY} | |
legislatorInfo = requests.get(lookupRequest) | |
jsonResponseRealNames = json.loads(legislatorInfo.text) | |
if jsonResponseRealNames[u'results']: | |
firstName = jsonResponseRealNames[u'results'][0][u'first_name'] | |
lastName = jsonResponseRealNames[u'results'][0][u'last_name'] | |
print bioKey+": "+lastName+", "+firstName | |
else: | |
print bioKey+": Name not found" | |
# Another way... | |
# pelosi = congress.legislators(lastname='Pelosi')[0] | |
# representative = congress.legislators(bioguide_id='S001141') | |
# pprint.pprint(representative) | |
################################################## | |
# To create breakpoints, use: | |
# import pdb | |
# pdb.set_trace() | |
# Type 'q' to stop trace | |
################################################## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment