forked from CSE-312/CSE312-Website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcse312_app.py
58 lines (43 loc) · 1.64 KB
/
cse312_app.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
49
50
51
52
53
54
55
56
57
58
import json
from flask import Flask, send_from_directory, render_template, request, make_response
from flask_socketio import SocketIO, emit
app = Flask(__name__)
socket_server = SocketIO(app)
content_directory = "content/"
content_root = content_directory + "cse312.json"
def load_content(content_filename):
all_content = []
with open(content_filename) as content_file:
content = json.load(content_file)
for week in content:
with open(content_directory + week) as week_file:
all_content.append(json.load(week_file))
return all_content
@app.get('/')
def cse312():
content = load_content(content_root)
resp = make_response(render_template('cse312/cse312.html', weeks=content))
resp.headers["X-Content-Type-Options"] = "nosniff"
return resp
@app.get('/hw/<hw_url>')
def hw(hw_url):
resp = make_response(render_template('hw/' + str(hw_url)))
resp.headers["X-Content-Type-Options"] = "nosniff"
return resp
@app.route('/static_files/<path:filename>')
def serve_static(filename):
resp = make_response(send_from_directory('static_files', filename))
resp.headers["X-Content-Type-Options"] = "nosniff"
return resp
@app.route('/rec')
def recitation_attendance_tool():
resp = make_response(render_template("cse312/recAttendance.html"))
resp.headers["X-Content-Type-Options"] = "nosniff"
return resp
@app.route('/failMe', methods=["GET", "POST"])
def example_test():
resp = make_response("You may have been hacked..")
resp.headers["Access-Control-Allow-Origin"] = "*"
return resp
if __name__ == '__main__':
socket_server.run(app, host="0.0.0.0", port=5000)