From 16abb24878e3145a036ef508eb532e318f587378 Mon Sep 17 00:00:00 2001 From: Ultrablob Date: Mon, 31 Mar 2025 14:07:21 -0400 Subject: [PATCH] allow parsing from text files (for calendars on whiteboard) --- compsci.txt | 4 ++++ parse_txt.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 compsci.txt create mode 100644 parse_txt.py diff --git a/compsci.txt b/compsci.txt new file mode 100644 index 0000000..3caf18b --- /dev/null +++ b/compsci.txt @@ -0,0 +1,4 @@ +Inheritance +Lab Day 1 - Code Tracing +Lab Day 2 - Coding +Lab Day 3 - Coding diff --git a/parse_txt.py b/parse_txt.py new file mode 100644 index 0000000..fbce2a1 --- /dev/null +++ b/parse_txt.py @@ -0,0 +1,36 @@ +from json import load +from datetime import time, datetime, timedelta +from ical.calendar import Calendar +from ical.event import Event +from ical.calendar_stream import IcsCalendarStream +from pathlib import Path + +calendar = Calendar() +CLASS = "compsci" + +CLASS_START = time(hour=1+12, minute=30) +CLASS_END = time(hour=2+12, minute=45) + +this_monday = datetime.today() +if datetime.now().weekday == 4: # is a friday, go to next week + this_monday += timedelta(days=-this_monday.weekday(), weeks=1) # black magic +else: # not a friday, go to this week + this_monday -= timedelta(days=this_monday.weekday()) # black magic + +print(this_monday) + +weekday = 0 + +for title in Path("compsci.txt").read_text().splitlines(): + day = this_monday + timedelta(days=weekday) + weekday += 1 + + if title.strip == "": + continue + + calendar.events.append( + Event(summary=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)) \ No newline at end of file