API reference

KrogocoIcs fetches a calendar page and builds the ICS data. Each scraped entry is a CalendarEvent, which you get from scrape_events() if you want the events without the ICS step.

class krogoco_calendar.KrogocoIcs(url, months, blacklist=None)[source]

Screen scrapes Krog & Co’s calendar page and produces ICS output.

The scraper walks the <h3> elements on the calendar page, which follow this structure:

  • Month headers (e.g. "februari")

  • Date lines (e.g. "torsdag 05/02")

  • Event links (<a href="...">Event Title</a>)

Year rollover is detected automatically when the month number decreases (e.g. December → January).

Parameters:
  • url (str) – The URL to the Krog & Co calendar page.

  • months (int) – Number of months into the future to include.

  • blacklist (list[str] | None) – Optional list of strings. Events whose title contains any of these strings (case-insensitive) will be excluded.

Example usage:

scraper = KrogocoIcs(
    url="https://krogoco.se/jonkoping/kalender/",
    months=2,
    blacklist=["HV71", "SHL"],
)
scraper.write_ics("calendar.ics")
BASE_URL = 'https://krogoco.se'

Base URL used to resolve relative event links.

scrape_events()[source]

Scrape the calendar page and return a list of events.

Parses the <h3> element structure of the calendar page, extracting dates and event links. Events in the past and events beyond the configured months horizon are excluded. Events matching the blacklist are also skipped.

Returns:

A list of CalendarEvent instances in chronological order.

Return type:

list[CalendarEvent]

get_ics()[source]

Scrape the calendar and return it as an ICS string.

Returns:

The full calendar in iCalendar (RFC 5545) format.

Return type:

str

write_ics(path)[source]

Scrape the calendar and write the ICS data to a file.

Parameters:

path (str | Path) – Destination file path. Parent directories must exist.

Return type:

None

class krogoco_calendar.CalendarEvent(date, title, url, all_day=True, start_time=None, end_time=None)[source]

A single scraped calendar event.

Parameters:
  • date (date) – The date of the event.

  • title (str) – The display title of the event.

  • url (str) – The full URL to the event detail page.

  • all_day (bool) – True if the event has no specific start/end time.

  • start_time (str | None) – Start time as "HH:MM" string, or None for all-day events.

  • end_time (str | None) – End time as "HH:MM" string, or None if unknown.