Initial code

This commit is contained in:
Gabriel Augendre 2016-09-16 23:58:26 +02:00
parent d658dd9993
commit 2afdb2a659
4 changed files with 59 additions and 0 deletions

1
Procfile Normal file
View file

@ -0,0 +1 @@
web: python app.py

47
app.py Normal file
View file

@ -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()

10
requirements.txt Normal file
View file

@ -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

1
runtime.txt Normal file
View file

@ -0,0 +1 @@
python-3.5.2