-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAvailabilityBackend.py
More file actions
46 lines (33 loc) · 1.01 KB
/
AvailabilityBackend.py
File metadata and controls
46 lines (33 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
from flask import Flask, jsonify, request
from flask.ext.cors import CORS
import re
availability = {}
app = Flask(__name__)
CORS(app)
@app.route("/")
def hello_world():
return jsonify({"message": "Hello World!"})
@app.route("/availability")
def get_availability():
return jsonify(availability)
@app.route("/availability", methods=["POST"])
def record_availability():
global availability
json = request.get_json()
if not json:
return jsonify({"error": "not JSON"})
if len(json) != 1:
return jsonify({"error": "wrong len"})
safe = {}
for key in json:
value = json[key]
print(value, key)
key = re.sub('[<>*&#@$;:]', '', key)
value = re.sub('[<>*&#@;:]', '', value)
print(value, key)
if value == "Free" or value == "Busy" or value == "Putting out a fire" or value == "Running really fast":
safe[key] = value
availability.update(safe)
return jsonify(availability)
if __name__ == "__main__":
app.run(debug=True)