diff options
| author | Fuwn <[email protected]> | 2025-02-10 00:58:18 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-02-10 00:58:18 -0800 |
| commit | f68f7259cbd19cf7eb8d0693dd4c217ea60a775d (patch) | |
| tree | 24f906ec5cfc16461b35cf1c42e35437389cb6f7 /generate_icalendar.py | |
| parent | feat: initial release (diff) | |
| download | hololist-to-json-and-ical-f68f7259cbd19cf7eb8d0693dd4c217ea60a775d.tar.xz hololist-to-json-and-ical-f68f7259cbd19cf7eb8d0693dd4c217ea60a775d.zip | |
feat: icalendar generator
Diffstat (limited to 'generate_icalendar.py')
| -rw-r--r-- | generate_icalendar.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/generate_icalendar.py b/generate_icalendar.py new file mode 100644 index 0000000..a842f3b --- /dev/null +++ b/generate_icalendar.py @@ -0,0 +1,44 @@ +import json +from datetime import datetime +import icalendar + +with open("./hololive_birthdays.json", "r", encoding="utf-8") as file: + birthdays = json.load(file) + +calendar = icalendar.Calendar() + +calendar.add("prodid", "-//Fuwn//hololive & HOLOSTARS Birthday Calendar//EN") +calendar.add("version", "2.0") +calendar.add("calscale", "GREGORIAN") +calendar.add("method", "PUBLISH") +calendar.add("x-wr-calname", "hololive & HOLOSTARS Birthdays") +calendar.add("x-wr-timezone", "Asia/Tokyo") +calendar.add("x-wr-caldesc", "https://github.com/Fuwn/hololist-to-json-and-ical") + +# Hakos Baelz gets skipped if it's not a leap year. +current_year = 2024 + +for birthday in birthdays: + try: + event_date = datetime(current_year, birthday["month"], birthday["day"]) + event = icalendar.Event() + + event.add("summary", f"{birthday['name']}'s Birthday") + event.add( + "description", + f"HoloList Profile: {birthday['profileURL']}", + ) + event.add("dtstart", event_date.date()) + event.add("dtend", event_date.date()) + event.add("dtstamp", datetime.now()) + event.add("rrule", {"freq": "yearly"}) + event.add( + "uid", + f"{birthday['name'].replace(' ', '_').lower()}_{birthday['month']}{birthday['day']}@hololivepro.com", + ) + calendar.add_component(event) + except ValueError as e: + print(e) + +with open("hololive_birthdays.ics", "wb") as ics_file: + ics_file.write(calendar.to_ical()) |