School-Calendar-Import/parse_json.py
2025-01-20 11:15:14 -05:00

23 lines
No EOL
788 B
Python

from json import load
from datetime import time, datetime
from ical.calendar import Calendar
from ical.event import Event
from ical.calendar_stream import IcsCalendarStream
calendar = Calendar()
CLASS = "tech"
CLASS_START = time(hour=10, minute=52)
CLASS_END = time(hour=12, minute=7)
for key, value in load(open(f"{CLASS}.json")).items():
value = value.strip()
if value.lower() == "pa day" or value.lower() == "pd day" or "break" in value.lower():
continue
day = datetime.strptime(key, "%Y %B %d").date()
calendar.events.append(
Event(summary=value.title(), start=datetime.combine(day, CLASS_START), end=datetime.combine(day, CLASS_END))
)
with open(f"{CLASS}.ics", "w") as ics_file:
ics_file.write(IcsCalendarStream.calendar_to_ics(calendar))