A barebones python tool to fix the inconvenient and incorrect iCal format of the UQ timetable while still allowing subscription and auto-updating of events
https://topost.net/calfix
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
890 B
40 lines
890 B
3 years ago
|
import requests
|
||
|
|
||
|
|
||
|
def reformat_cal(url):
|
||
|
print(url)
|
||
|
req = requests.get(url)
|
||
|
if (req.status_code != 200):
|
||
|
raise ValueError()
|
||
|
|
||
|
if req.text == "" or req.text == None:
|
||
|
raise ValueError()
|
||
|
|
||
|
cal = req.text.split("\n")
|
||
|
|
||
|
for counter, line in enumerate(cal):
|
||
|
if "BEGIN:VEVENT" in line:
|
||
|
summary = None
|
||
|
desc = None
|
||
|
|
||
|
if "SUMMARY" in line:
|
||
|
summary = counter
|
||
|
continue
|
||
|
|
||
|
if "DESCRIPTION" in line:
|
||
|
desc = counter
|
||
|
continue
|
||
|
|
||
|
if "UID" in line:
|
||
|
cal[counter] = ""
|
||
|
|
||
|
if "END:VEVENT" in line:
|
||
|
course_code = cal[desc].split("_")[0].split(":")[1]
|
||
|
imsummary = cal[summary].split(',')
|
||
|
imsummary[0] = "SUMMARY:" + course_code
|
||
|
cal[summary] = ','.join(imsummary)
|
||
|
|
||
|
cal = "\n".join(cal)
|
||
|
return cal
|
||
|
|