-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
52 lines (41 loc) · 1.01 KB
/
Copy pathmain.py
File metadata and controls
52 lines (41 loc) · 1.01 KB
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
from flask import Flask, jsonify, request
from json import load
from flask_cors import CORS
data = {
"arithmetic": {
"q1": {
"question": "What is 100/25?",
"options": ["3", "4", "5", "6", "7"],
"correctIndex": 1
}
},
"algebra": {
"q1": {
"question": "What is 100/25?",
"options": ["3", "4", "5", "6", "7"],
"correctIndex": 1
}
}
}
PORT = 7777
app = Flask(__name__)
CORS(app)
error = {
"error": "Invalid access key."
}
@app.route("/")
def index():
return "<h1>Go to /api!<h1>"
@app.route("/mathsapi")
def api():
passed_data = request.args.to_dict()
given_key = passed_data["accesskey"]
if given_key == "ILoveMath":
# with open("data.json") as f:
# myData = load(f)
# return jsonify(myData)
return jsonify(data)
else:
return jsonify(error)
if __name__ == '__main__':
app.run(port=PORT)