Calendar: calendar.ical, calendar.google
calendar.ical
Fetches and parses a public ICS feed. This is the calendar source actually in use (see
configs/dev.yml’s stanstorp/school_work sources).
sources:
school_work:
source: calendar.ical
params:
url: https://cal.vklass.se/....ics
Params
- pydantic model todays_paper_web.widgets.calendar.ical.ICalendarParams[source]
Bases:
DataSourceParams
Returns
An ICalendarModel wrapping the parsed feed, with:
.walk(name=None)— delegates straight toicalendar.Calendar.walk().ical.walk('vevent')iterates everyVEVENTcomponent as-is, without expanding recurring events (a weeklyRRULEevent appears once, at its original occurrence, however far in the past)..eventsOn(day)/.eventsBetween(start, end)— use these instead when a screen needs “what’s happening today/this week”: they expand recurring events into their concrete occurrences within the given range viarecurring_ical_events, and return them sorted by start time.
{% for event in source("school_work").walk('vevent') %}
<text>{{ event.get('summary') }}</text>
{% endfor %}
calendar.google
Reads events from a Google Calendar via the Calendar API. Requires a one-time local OAuth login before it will return anything.
One-time setup
Create an OAuth client (Desktop app) in the Google Cloud Console for the Calendar API, and download its credentials as
google_client_secret.jsonin the server’s working directory.Run
uv run python todays_paper_web/widgets/calendar/google-cli.pyonce. It opens a browser login flow and writestoken.jsonnext to it, which is whatcalendar.googlereads at runtime; the token is refreshed automatically as long as it stays valid.
Params
Returns
A list of raw event dicts as returned by the Google Calendar API’s events.list, ordered by start time,
with each event’s start.dateTime parsed into a datetime. Returns {} if token.json doesn’t exist
yet (setup not done) or if the API call fails.