Skip to content

Instantly share code, notes, and snippets.

@edsu
Created October 3, 2022 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edsu/19dfd473bc9c40e3f1ec31f826790c4c to your computer and use it in GitHub Desktop.
Save edsu/19dfd473bc9c40e3f1ec31f826790c4c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# Use https://github.com/unitedstates/ data to get JSON for current members of
# congress including their social media accounts.
#
# Note: you will need to pip install requests and pyyaml
import json
import yaml
import requests
def main():
print(json.dumps(get_people(), indent=2))
def get_people():
people = {}
for person in get("https://raw.githubusercontent.com/unitedstates/congress-legislators/main/legislators-current.yaml"):
person['social'] = None
people[person['id']['bioguide']] = person
# join social media data
for social in get("https://raw.githubusercontent.com/unitedstates/congress-legislators/main/legislators-social-media.yaml"):
people[social['id']['bioguide']]['social'] = social['social']
return list(people.values())
def get(url):
"""Fetch and parse some YAML.
"""
return yaml.safe_load(requests.get(url).text)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment