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