forked from umalavasic/eAUrnik
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAPI.py
executable file
·48 lines (40 loc) · 1.58 KB
/
API.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#
# API.py
# eAUrnik
#
import Timetable
from flask import Flask, make_response
from flask_restful import Api
from flask_cors import CORS
app = Flask(__name__)
api = Api(app)
CORS(app)
@app.errorhandler(404)
def page_not_found(e):
response = make_response("This request could not be processed. Check the provided information and try again.", 400)
response.headers["content-type"] = "application/json"
return response
@app.route("/urniki/<string:school>/razredi/<int:class_>/dijak/<int:student>")
def get_student(school, class_, student):
"""Parse a student's calendar."""
timetable = Timetable.get_student(school, class_, student)
response = make_response(timetable, 200)
response.headers["content-type"] = "text/calendar"
return response
@app.route("/urniki/<string:school>/razredi/<int:class_>")
def get_class(school, class_):
"""Parse a class's calendar."""
timetable = Timetable.get_class(school, class_)
response = make_response(timetable, 200)
response.headers["content-type"] = "text/calendar"
return response
@app.route("/urniki/<string:school>/ucitelj/<int:teacher>")
@app.route("/urniki/<string:school>/ucitelj/<int:teacher>/tednov/<int:weeks>")
def get_teacher_weeks(school, teacher, weeks=1):
"""Parse a teacher's calender for multiple weeks ahead. If number of weeks isn't specified, defaults to 1."""
timetable = Timetable.get_teacher(school, teacher, weeks)
response = make_response(timetable, 200)
response.headers["content-type"] = "text/calendar"
return response
if __name__ == "__main__":
app.run(host = "::")