allow parsing from text files (for calendars on whiteboard)
This commit is contained in:
parent
5492068022
commit
16abb24878
2 changed files with 40 additions and 0 deletions
36
parse_txt.py
Normal file
36
parse_txt.py
Normal file
|
@ -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))
|
Loading…
Add table
Add a link
Reference in a new issue