From 04baff10a6a116eb1a9f8c5442cf103de468a38a Mon Sep 17 00:00:00 2001 From: Scott Wallace Date: Tue, 7 May 2024 13:20:29 +0100 Subject: [PATCH] Move to the `ics` library --- main.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index c38b657..e5981e8 100644 --- a/main.py +++ b/main.py @@ -4,7 +4,7 @@ Generated by ChatGPT 3.5 (https://chatgpt.com/c/103d4f23-7c8f-484f-9598-d38187e9 from datetime import datetime, timedelta -from icalendar import Calendar, Event +from ics import Calendar, Event def mothering_sunday(year: int) -> datetime: # pylint: disable=too-many-locals @@ -45,8 +45,6 @@ def generate_ical() -> None: Generate an ICAL file for Mothering Sunday (UK) """ cal = Calendar() - cal.add("prodid", "-//Mothering Sunday Calendar//wallace.sh//") - cal.add("version", "2.0") for year in range(datetime.now().year, datetime.now().year + 10): date = mothering_sunday(year) @@ -54,13 +52,13 @@ def generate_ical() -> None: if date.weekday() != 6: # 6 corresponds to Sunday date += timedelta(days=6 - date.weekday()) event = Event() - event.add("summary", "Mothering Sunday") - event.add("dtstart", date) - event.add("dtend", date + timedelta(days=1)) - cal.add_component(event) + event.name = "Mothering Sunday" + event.begin = date + event.make_all_day() + cal.events.add(event) - with open("mothering_sunday.ics", "wb") as f: - f.write(cal.to_ical()) + with open("mothering_sunday.ics", "w", encoding="utf-8") as f: + f.write(cal.serialize()) if __name__ == "__main__":