Request proper URL for agenda given year and group

This commit is contained in:
Gabriel Augendre 2016-09-17 12:37:00 +02:00
parent e536d1a529
commit 3330a2df11
No known key found for this signature in database
GPG key ID: D2B6A5B41FC438B1

14
app.py
View file

@ -7,10 +7,8 @@ app = Flask(__name__)
FILTERED_COURSES = os.environ.get('COURSES', '').split(',') FILTERED_COURSES = os.environ.get('COURSES', '').split(',')
FILTERED_TYPES = os.environ.get('TYPES', '').split(',') FILTERED_TYPES = os.environ.get('TYPES', '').split(',')
YEAR = int(os.environ.get('YEAR', '4')) YEAR = os.environ.get('YEAR', '4')
GROUP = int(os.environ.get('GROUP', '1')) GROUP = os.environ.get('GROUP', '1')
GENERAL_GROUP = int(os.environ.get('GENERAL_GROUP', '0'))
GROUPS = [GROUP, GENERAL_GROUP]
@app.route("/") @app.route("/")
@ -19,6 +17,7 @@ def hello():
if url is None: if url is None:
return "" return ""
url += "&promo={year}&groupe={group}".format(year=YEAR, group=GROUP)
cal_str = urllib.request.urlopen(url).read() cal_str = urllib.request.urlopen(url).read()
cal = Component.from_ical(cal_str) cal = Component.from_ical(cal_str)
@ -42,15 +41,10 @@ def hello():
def should_add(event): def should_add(event):
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]
year = event['SUMMARY'][0]
group = event['SUMMARY'][-1]
return \ return \
course_code not in FILTERED_COURSES \ course_code not in FILTERED_COURSES \
and course_type not in FILTERED_TYPES \ 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))