Skip to content

Instantly share code, notes, and snippets.

@gregjurman
Last active October 30, 2015 22:48
Show Gist options
  • Save gregjurman/1d447ce8182ee1d96e92 to your computer and use it in GitHub Desktop.
Save gregjurman/1d447ce8182ee1d96e92 to your computer and use it in GitHub Desktop.
List the names of all OpenFEC beta candidates
import requests
import json
# docs: https://api.open.fec.gov/developers
API_KEY = "........"
API_VERSION = "v1"
API_URL = "https://api.open.fec.gov/v1/candidates"
def main():
query = dict(api_key=API_KEY,
per_page=100,
page=1,
cycle=2016,
sort_hide_null=True,
sort="name")
r = requests.get(API_URL, params=query)
j = json.loads(r.text)
a = [x['name'] for x in j['results']]
for i in range(2,int(j['pagination']['pages'])+1):
query['page']=i
r = requests.get(API_URL, params=query)
j = json.loads(r.text)
a.extend([x['name'] for x in j['results']])
for b in a:
print b
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment