Skip to content

Instantly share code, notes, and snippets.

@mursts
Created October 5, 2014 16:27
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 mursts/6234889c163877e70f3f to your computer and use it in GitHub Desktop.
Save mursts/6234889c163877e70f3f to your computer and use it in GitHub Desktop.
GoogleCalendarから祝日を取得する
#!/usr/bin/env python
# coding: utf-8
import datetime
import requests
URL = 'http://www.google.com/calendar/' \
'feeds/ja.japanese%23holiday@group.v.calendar.google.com/' \
'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