kobo-wall-calendar/google_calendar.py

33 lines
813 B
Python
Raw Normal View History

2023-09-17 20:35:27 +00:00
import functools
import requests_cache
from ical.calendar_stream import IcsCalendarStream
import datetime
import logging
logger = logging.getLogger(__name__)
SESSION = requests_cache.CachedSession('calendar')
@functools.cache
def get_events_for_month(ical_link, today):
logger.warning('Downloading ical from Google')
response = SESSION.get(ical_link)
assert response.status_code == 200
logger.warning('Loading ical')
calendar = IcsCalendarStream.calendar_from_ics(response.text)
today = datetime.date.today()
logger.warning('Iterating ical')
date = today.replace(day = 1)
stuff = []
while date.month == today.month:
for e in calendar.timeline.on_date(date):
stuff.append((date, e))
date += datetime.timedelta(days = 1)
return stuff