Created
October 5, 2014 16:27
-
-
Save mursts/6234889c163877e70f3f to your computer and use it in GitHub Desktop.
GoogleCalendarから祝日を取得する
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
#!/usr/bin/env python | |
# coding: utf-8 | |
import datetime | |
import requests | |
URL = 'http://www.google.com/calendar/' \ | |
'feeds/ja.japanese%[email protected]/' \ | |
'public/full' | |
def get_holidays(min_date, max_date): | |
payload = {'start-min': min_date.strftime('%Y-%m-%d'), | |
'start-max': max_date.strftime('%Y-%m-%d'), | |
'alt': 'json'} | |
r = requests.get(URL, params=payload) | |
json = r.json() | |
holidays = [] | |
if not 'entry' in json['feed']: | |
return holidays | |
for entry in json['feed']['entry']: | |
date = entry['gd$when'][0]['startTime'] | |
date = datetime.datetime.strptime(date, '%Y-%m-%d') | |
holidays.append((date, entry['title']['$t'],)) | |
holidays.sort(key=lambda holiday: holiday[0]) | |
return holidays | |
def main(): | |
holidays = get_holidays(datetime.date(2014, 1, 1), | |
datetime.date(2014, 12, 31)) | |
for holiday in holidays: | |
print('{}: {}'.format(holiday[0], holiday[1])) | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment