Skip to content

Instantly share code, notes, and snippets.

@palewire
Last active October 28, 2018 22:14
Show Gist options
  • Save palewire/6ae639f69ce2209501374f7b471addbb to your computer and use it in GitHub Desktop.
Save palewire/6ae639f69ce2209501374f7b471addbb to your computer and use it in GitHub Desktop.
Download all members of Congress from ProPublica's Represent API
import csv
from congress import Congress
REPRESENT_API_KEY = '<API KEY>'
congress = Congress(REPRESENT_API_KEY)
house = list(congress.members.filter("house")[0]['members'])
reps = [m for m in house if m['title'] == 'Representative']
in_office = [m for m in reps if m['in_office'] is True]
outpath = "members.csv"
print("Writing {} members to {}".format(len(in_office), outpath))
with open(outpath, "w") as fp:
writer = csv.DictWriter(fp, fieldnames=in_office[0].keys())
writer.writeheader()
writer.writerows(in_office)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment