-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
38 lines (30 loc) · 1.01 KB
/
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
import json
from flask_cors import CORS
from flask import Flask
from flask import request
from flask import Response
app = Flask(__name__)
CORS(app)
def html(content): # Also allows you to set your own <head></head> etc
return '<html><br /><body>' + content + '</body></html>'
@app.route('/')
def index():
return open('./Website/index.html').read()
@app.route('/search/<string:className>')
def search(className):
res = classdic[className]
buildStr = ""
buildStr += '<h1>' + res['fullName'] + '</h1><p className="body">'
for key, value in res.items():
if key != 'fullName':
buildStr += key + ': ' + str(value) + '<br />'
buildStr += '<p>'
return html(buildStr)
if __name__ == '__main__': #Create class dictionary
with open('classdata.json','r', encoding='utf8') as file:
dic = file.read()
dic = json.loads(dic)['classes']
classdic = {}
for nbr,data in dic.items():
classdic[data['name']] = data
app.run(debug=True,host='0.0.0.0',port=8081)