-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
63 lines (46 loc) · 1.73 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# converts the results into API format
from flask import Flask, Response, jsonify, render_template
import db
import ai
import json
import rmp
app = Flask(__name__)
@app.route('/')
def home():
return render_template("index.html", title="Home", data=db.getRandomFrontend(3))
@app.route('/teacher/<int:id>')
def teacher(id):
return render_template("view.html", id=id, title="Teacher")
@app.route('/how-it-works')
def works():
return render_template("how.html", title="How it Works")
@app.route('/_api/getTeacherByID/<int:id>', methods=['GET'])
def get_data(id):
id = int(id)
return Response(db.apiSelectTeacher(id), content_type="application/json")
@app.route('/_api/getTeacherSummary/<int:id>', methods=['GET'])
def get_summary(id):
id = int(id)
data = db.apiSelectTeacher(id)
if data == {} or json.loads(data) == {}:
return jsonify({"message": "Teacher not found"}), 404
data = json.loads(data)
goodString = ""
badString = ""
for goodComment in data["all_good_comments"]:
goodString += goodComment + ", "
for badComment in data["all_bad_comments"]:
badString += badComment + ", "
good = ai.summarize("positive", goodString)
bad = ai.summarize("critical", badString)
return jsonify({"positive": good, "critical": bad})
@app.route('/_api/searchTeacher/<q>', methods=['GET'])
def search(q):
return Response(json.dumps(db.searchTeacher(q)), content_type="application/json")
# not implemented on frontend, far too slow
@app.route('/_api/rmpBackend/<q>')
def rate(q):
return Response(json.dumps(rmp.getRating(q)), content_type="application/json")
# Start the server
if __name__ == '__main__':
app.run(debug=False, port=5000)