Last active
October 28, 2018 22:14
-
-
Save palewire/6ae639f69ce2209501374f7b471addbb to your computer and use it in GitHub Desktop.
Download all members of Congress from ProPublica's Represent API
This file contains 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 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