Allow filtering group, year and course type
This commit is contained in:
parent
0ff469a195
commit
e536d1a529
1 changed files with 22 additions and 4 deletions
26
app.py
26
app.py
|
@ -5,6 +5,13 @@ from icalendar.cal import Calendar, Component
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
FILTERED_COURSES = os.environ.get('COURSES', '').split(',')
|
||||||
|
FILTERED_TYPES = os.environ.get('TYPES', '').split(',')
|
||||||
|
YEAR = int(os.environ.get('YEAR', '4'))
|
||||||
|
GROUP = int(os.environ.get('GROUP', '1'))
|
||||||
|
GENERAL_GROUP = int(os.environ.get('GENERAL_GROUP', '0'))
|
||||||
|
GROUPS = [GROUP, GENERAL_GROUP]
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def hello():
|
def hello():
|
||||||
|
@ -14,8 +21,6 @@ def hello():
|
||||||
|
|
||||||
cal_str = urllib.request.urlopen(url).read()
|
cal_str = urllib.request.urlopen(url).read()
|
||||||
|
|
||||||
FILTERED_EVENTS = os.environ.get('COURSES', '').split(',')
|
|
||||||
|
|
||||||
cal = Component.from_ical(cal_str)
|
cal = Component.from_ical(cal_str)
|
||||||
other = Calendar()
|
other = Calendar()
|
||||||
|
|
||||||
|
@ -28,12 +33,25 @@ def hello():
|
||||||
|
|
||||||
# Filter and copy VEVENTs
|
# Filter and copy VEVENTs
|
||||||
for ev in cal.walk('VEVENT'):
|
for ev in cal.walk('VEVENT'):
|
||||||
course_code = ev['SUMMARY'].split('-')[1].split('/')[0]
|
if should_add(ev):
|
||||||
if course_code not in FILTERED_EVENTS:
|
|
||||||
other.add_component(ev)
|
other.add_component(ev)
|
||||||
|
|
||||||
return other.to_ical().replace(b'\r\n', b'\n').strip()
|
return other.to_ical().replace(b'\r\n', b'\n').strip()
|
||||||
|
|
||||||
|
|
||||||
|
def should_add(event):
|
||||||
|
course_code = event['SUMMARY'].split('-')[1].split('/')[0]
|
||||||
|
course_type = event['SUMMARY'].split('/')[1].split('_')[1]
|
||||||
|
year = event['SUMMARY'][0]
|
||||||
|
group = event['SUMMARY'][-1]
|
||||||
|
|
||||||
|
return \
|
||||||
|
course_code not in FILTERED_COURSES \
|
||||||
|
and course_type not in FILTERED_TYPES \
|
||||||
|
and year == YEAR \
|
||||||
|
and group in GROUPS
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
port = int(os.environ.get('PORT', 5000))
|
port = int(os.environ.get('PORT', 5000))
|
||||||
app.run('0.0.0.0', port)
|
app.run('0.0.0.0', port)
|
||||||
|
|
Loading…
Reference in a new issue