From 2afdb2a659236acb088d50a942579713ec46ad52 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Fri, 16 Sep 2016 23:58:26 +0200 Subject: [PATCH] Initial code --- Procfile | 1 + app.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 10 ++++++++++ runtime.txt | 1 + 4 files changed, 59 insertions(+) create mode 100644 Procfile create mode 100644 app.py create mode 100644 requirements.txt create mode 100644 runtime.txt diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..e6cb5ad --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: python app.py \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..a3efca8 --- /dev/null +++ b/app.py @@ -0,0 +1,47 @@ +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() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6a4dfca --- /dev/null +++ b/requirements.txt @@ -0,0 +1,10 @@ +click==6.6 +Flask==0.11.1 +icalendar==3.10 +itsdangerous==0.24 +Jinja2==2.8 +MarkupSafe==0.23 +python-dateutil==2.5.3 +pytz==2016.6.1 +six==1.10.0 +Werkzeug==0.11.11 diff --git a/runtime.txt b/runtime.txt new file mode 100644 index 0000000..5f61493 --- /dev/null +++ b/runtime.txt @@ -0,0 +1 @@ +python-3.5.2 \ No newline at end of file