add to git
This commit is contained in:
commit
2956a715e3
5 changed files with 91 additions and 0 deletions
30
parse_csv.py
Normal file
30
parse_csv.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
from csv import reader
|
||||
from datetime import date, time, datetime
|
||||
from ical.calendar import Calendar
|
||||
from ical.event import Event
|
||||
from ical.calendar_stream import IcsCalendarStream
|
||||
from re import sub
|
||||
|
||||
def cleanup(text):
|
||||
return sub(r' {2,}', " ", text.replace("\t", " ")).strip().replace("Quiz", "Quiz +")
|
||||
|
||||
calendar = Calendar()
|
||||
|
||||
CLASS_START = time(hour=9, minute=33)
|
||||
CLASS_END = time(hour=10, minute=48)
|
||||
|
||||
math = list(reader(open('MPM2D Calendar Semester 1.csv', newline='')))
|
||||
dates = []
|
||||
for i in range(0, len(math), 2):
|
||||
for k in range(len(math[i])):
|
||||
event = cleanup(math[i+1][k])
|
||||
if event.lower() == "pa day" or event.lower() == "pd day" or "break" in event.lower():
|
||||
continue
|
||||
year = "2025 " if "January" in math[i][k] else "2024 "
|
||||
day = datetime.strptime(year + math[i][k], "%Y %B %d").date()
|
||||
calendar.events.append(
|
||||
Event(summary=event, start=datetime.combine(day, CLASS_START), end=datetime.combine(day, CLASS_END))
|
||||
)
|
||||
|
||||
with open("math.ics", "w") as ics_file:
|
||||
ics_file.write(IcsCalendarStream.calendar_to_ics(calendar))
|
Loading…
Add table
Add a link
Reference in a new issue