-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrunserver.py
executable file
·29 lines (22 loc) · 942 Bytes
/
runserver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import Flask, render_template, request, Response, flash, redirect, url_for
from grabber import sfu, LoginError
from data import get_years, get_semesters
app = Flask(__name__)
app.secret_key = '8g789erobgyekhlwctybgwy4j93xft6'
@app.route('/')
def index():
return render_template('index.html', years=get_years(), semesters=get_semesters())
@app.route('/grab', methods=['POST'])
def grab():
try:
student_name, calendar = sfu(request.form['username'], request.form['password'], request.form['alert'], request.form['year'], request.form['semester'])
except (LoginError, ValueError) as e:
flash(e.error)
return redirect(url_for('index'))
else:
headers = {'Content-Disposition': 'attachment; filename=' + student_name}
return Response(calendar, headers=headers, mimetype='text/calendar')
if __name__ == '__main__':
app.run()