From 95f02eb0c9bcfd456d32cbf377b01574dc6c1590 Mon Sep 17 00:00:00 2001 From: fram3d Date: Thu, 8 Feb 2024 16:50:05 +0100 Subject: [PATCH] add ical page --- prep.py | 36 ++++++++++++++++++++++++++++++++++++ template/end.ical | 1 + template/event.ical | 13 +++++++++++++ template/head.ical | 20 ++++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 template/end.ical create mode 100644 template/event.ical create mode 100644 template/head.ical diff --git a/prep.py b/prep.py index 6e2c582c..219e656d 100755 --- a/prep.py +++ b/prep.py @@ -45,6 +45,35 @@ def build_html(events: list[dict], dayNames: list[str]) -> str: events_html.append(f"\n
{event_html}
") return events_html +def build_ical(events: list[dict]) -> str: + today = datetime.today().now() + # Header + events_ical = "" + with open("template/head.ical", "r") as file: + events_ical += file.read() + # Events + for event in events: + title = event["title"] + location = event["location"] + date = event["date"] + date = str(date.year) + str(date.month).zfill(2) + str(date.day).zfill(2) + created = str(today.year) + str(today.month).zfill(2) + str(today.day).zfill(2) + "T" + str(today.hour).zfill(2) + str(today.minute).zfill(2) + str(today.second).zfill(2) + "Z" + time = event["time"] + date = date + "T" + time.replace(":", "") + "00" + + event_template = "" + with open("template/event.ical", "r") as file: + event_template += file.read() + event_template = event_template.replace("", created) + event_template = event_template.replace("", date) + event_template = event_template.replace("", title) + + events_ical += event_template + # Footer + with open("template/end.ical", "r") as file: + events_ical += file.read() + return events_ical + events = sorted(load_events("dogadjaji.csv"), key=lambda e: e["date"]) today = datetime.today().date() @@ -87,3 +116,10 @@ with open("pages/en/events_archive.html", "r") as file: with open("pages/en/events_archive.html", "w") as file: file.writelines(page_template + past_events_html) + +new_events_ical = build_ical(new_events) + +# Build ical +with open("site/events.ical", "w") as file: + file.write(build_ical) + diff --git a/template/end.ical b/template/end.ical new file mode 100644 index 00000000..b0bb4bc9 --- /dev/null +++ b/template/end.ical @@ -0,0 +1 @@ +END:VCALENDAR diff --git a/template/event.ical b/template/event.ical new file mode 100644 index 00000000..cd1e8d00 --- /dev/null +++ b/template/event.ical @@ -0,0 +1,13 @@ +BEGIN:VEVENT +UID:calendar.462701.field_date_time.0@dmz.rs +DTSTAMP: +CREATED: +DTSTART;TZID=Europe/Belgrade: +DTEND;TZID=Europe/Belgrade: +GEO:+44.805613;+20.479234 +LAST-MODIFIED:20240102T222415Z +LOCATION:DC Krov\, Kraljice Marije 47\, 6\, Beograd\, Serbia +STATUS:CONFIRMED +SUMMARY: +URL;TYPE=URI:https://dmz.rs +END:VEVENT diff --git a/template/head.ical b/template/head.ical new file mode 100644 index 00000000..0deb7ac1 --- /dev/null +++ b/template/head.ical @@ -0,0 +1,20 @@ +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//Date iCal v3.8//NONSGML kigkonsult.se iCalcreator 2.20.2// +METHOD:PUBLISH +X-WR-CALNAME;VALUE=TEXT:Decentrala events +BEGIN:VTIMEZONE +TZID:Europe/Belgrade +BEGIN:STANDARD +DTSTART:20231029T030000 +TZOFFSETFROM:+0200 +TZOFFSETTO:+0100 +TZNAME:CET +END:STANDARD +BEGIN:DAYLIGHT +DTSTART:20240331T020000 +TZOFFSETFROM:+0100 +TZOFFSETTO:+0200 +TZNAME:CEST +END:DAYLIGHT +END:VTIMEZONE