-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
54 lines (39 loc) · 1.2 KB
/
server.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
# -*- coding: utf-8 -*-
import random
import re
import datetime
from flask import Flask, render_template, jsonify, request, send_from_directory
app = Flask(__name__)
reservation_index = 0
reservations=[]
@app.route("/api/reservations", methods=["GET", "POST"])
def get_reservations():
global reservation_index
if request.method == "GET":
return jsonify({"reservations": reservations})
else:
reservation = {
"id": reservation_index,
"created": datetime.datetime.now(),
"name": request.json["name"],
"state": "Waiting"
}
reservations.append(reservation)
reservation_index += 1
return jsonify({"reservation": reservation})
@app.route("/api/reservations/next", methods=["POST"])
def goto_next_reservation():
for i in [r for r in reservations if r["state"] == "Helping"]:
i["state"] = "Helped"
waiting = [r for r in reservations if r["state"] == "Waiting"]
if len(waiting) > 0:
waiting[0]["state"] = "Helping"
return jsonify({"reservations": reservations})
@app.route('/')
def root():
return app.send_static_file('index.html')
@app.route('/js/<path:path>')
def send_js(path):
return send_from_directory('js', path)
if __name__ == '__main__':
app.run(debug=True, host="0.0.0.0")