Allow user to specify courses and types to exclude

This commit is contained in:
Gabriel Augendre 2016-09-17 13:27:46 +02:00
parent 5d960bd69d
commit 850dc2fdcc
No known key found for this signature in database
GPG key ID: D2B6A5B41FC438B1

29
app.py
View file

@ -7,9 +7,9 @@ app = Flask(__name__)
EXCLUDED_COURSES = os.environ.get('COURSES', '').split(',') EXCLUDED_COURSES = os.environ.get('COURSES', '').split(',')
EXCLUDED_TYPES = os.environ.get('TYPES', '').split(',') EXCLUDED_TYPES = os.environ.get('TYPES', '').split(',')
YEAR = os.environ.get('YEAR', '4') YEAR = os.environ.get('YEAR', '4')
GROUP = os.environ.get('GROUP', '1') GROUP = os.environ.get('GROUP', '1')
ALLOWED_YEARS = os.environ.get('ALLOWED_YEARS', '3,4,5').split(',') ALLOWED_YEARS = os.environ.get('ALLOWED_YEARS', '3,4,5').split(',')
ALLOWED_GROUPS = os.environ.get('ALLOWED_GROUPS', '1,2,3').split(',') ALLOWED_GROUPS = os.environ.get('ALLOWED_GROUPS', '1,2,3').split(',')
@ -59,12 +59,35 @@ def hello():
def should_add(event): def should_add(event):
"""
Determines whether an event should be added to the returned calendar or not.
:param event: The event to determine if should be added or not.
:type event: Component
:return: True if the event should be added, False otherwise.
:rtype: bool
"""
course_code = event['SUMMARY'].split('-')[1].split('/')[0] course_code = event['SUMMARY'].split('-')[1].split('/')[0]
course_type = event['SUMMARY'].split('/')[1].split('_')[1] course_type = event['SUMMARY'].split('/')[1].split('_')[1]
# Get user specified excluded courses/types if exist
excluded_courses = request.args.get('excluded_courses', '')
excluded_types = request.args.get('excluded_types', '')
if excluded_courses == '':
excluded_courses = EXCLUDED_COURSES
else:
excluded_courses = excluded_courses.split(',')
if excluded_types == '':
excluded_types = EXCLUDED_TYPES
else:
excluded_types = excluded_types.split(',')
# Filter against courses and types
return \ return \
course_code not in EXCLUDED_COURSES \ course_code not in excluded_courses \
and course_type not in EXCLUDED_TYPES and course_type not in excluded_types
if __name__ == "__main__": if __name__ == "__main__":
port = int(os.environ.get('PORT', 5000)) port = int(os.environ.get('PORT', 5000))