add to git
This commit is contained in:
commit
2956a715e3
5 changed files with 91 additions and 0 deletions
BIN
.DS_Store
vendored
Normal file
BIN
.DS_Store
vendored
Normal file
Binary file not shown.
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
*.json
|
||||
*.ics
|
||||
*.csv
|
||||
.venv/
|
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))
|
23
parse_json.py
Normal file
23
parse_json.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
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))
|
34
parse_tech_csv.py
Normal file
34
parse_tech_csv.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
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=10, minute=52)
|
||||
CLASS_END = time(hour=12, minute=7)
|
||||
|
||||
tech = list(reader(open('Tech Calendar 2024-2025 Grade 10.1.csv', newline='')))
|
||||
dates = []
|
||||
for i in range(0, len(tech), 4):
|
||||
for k in range(len(tech[i])):
|
||||
if tech[i+1][k]:
|
||||
event = tech[i+1][k].title()
|
||||
else:
|
||||
event = (tech[i+2][k].title() + " & " + tech[i+3][k].title()).strip(" & ")
|
||||
if event == "" or event.lower() == "pa day" or event.lower() == "pd day" or "break" in event.lower():
|
||||
continue
|
||||
year = "2025 " if "January" in tech[i][k] else "2024 "
|
||||
day = datetime.strptime(year + tech[i][k], "%Y %B %d").date()
|
||||
print(f"{day=} {event=}")
|
||||
calendar.events.append(
|
||||
Event(summary=event, start=datetime.combine(day, CLASS_START), end=datetime.combine(day, CLASS_END))
|
||||
)
|
||||
|
||||
with open("tech.ics", "w") as ics_file:
|
||||
ics_file.write(IcsCalendarStream.calendar_to_ics(calendar))
|
Loading…
Add table
Add a link
Reference in a new issue