48 lines
983 B
Python
48 lines
983 B
Python
from flask import Flask
|
|
import urllib.request
|
|
from icalendar.cal import Calendar, Component
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
@app.route("/")
|
|
def hello():
|
|
cal_str = urllib.request.urlopen(
|
|
"***REMOVED***").read()
|
|
|
|
FILTERED_EVENTS = [
|
|
'MGL',
|
|
'SYD',
|
|
'SQE',
|
|
'COM',
|
|
'RSM',
|
|
'ANG1',
|
|
'DLG',
|
|
'SPO',
|
|
'STA1',
|
|
'PST',
|
|
'SEC',
|
|
'DIA'
|
|
]
|
|
|
|
cal = Component.from_ical(cal_str)
|
|
other = Calendar()
|
|
|
|
# Copy all properties of calendar
|
|
for k, v in cal.items():
|
|
other.add(k, v)
|
|
|
|
# Copy the VTIMEZONE component
|
|
other.add_component(cal.walk('VTIMEZONE')[0])
|
|
|
|
# Filter and copy VEVENTs
|
|
for ev in cal.walk('VEVENT'):
|
|
course_code = ev['SUMMARY'].split('-')[1].split('/')[0]
|
|
if course_code not in FILTERED_EVENTS:
|
|
other.add_component(ev)
|
|
|
|
return other.to_ical().replace(b'\r\n', b'\n').strip()
|
|
|
|
if __name__ == "__main__":
|
|
app.run()
|