Created
March 27, 2014 20:03
-
-
Save jcarbaugh/9817053 to your computer and use it in GitHub Desktop.
Happy birthday, Congress!
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
import datetime | |
import sys | |
import icalendar | |
import requests | |
SUNLIGHT_KEY = sys.argv[1] | |
URL = 'https://congress.api.sunlightfoundation.com/legislators' | |
FIELDS = ('title', 'first_name', 'nickname', 'last_name', | |
'name_suffix', 'birthday', 'party', 'state', 'district') | |
PARAMS = { | |
'apikey': SUNLIGHT_KEY, | |
'per_page': 'all', | |
'fields': ','.join(FIELDS), | |
} | |
def parse_date(s): | |
return datetime.datetime.strptime(s, '%Y-%m-%d') | |
resp = requests.get(URL, params=PARAMS) | |
data = resp.json() | |
cal = icalendar.Calendar() | |
for moc in data['results']: | |
event = icalendar.Event() | |
summary = "%s. %s %s (%s-%s)" % (moc['title'], moc['first_name'], | |
moc['last_name'], moc['party'], moc['state']) | |
bday_start = parse_date(moc['birthday']) | |
bday_end = bday_start + datetime.timedelta(days=1) | |
event.add('summary', summary) | |
event.add('dtstart', bday_start.date()) | |
# event.add('dtend', bday_end) | |
event.add('rrule', {'freq': 'yearly'}) | |
cal.add_component(event) | |
sys.stdout.write(cal.to_ical()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment