-
Notifications
You must be signed in to change notification settings - Fork 592
/
server.py
62 lines (45 loc) · 1000 Bytes
/
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
55
56
57
58
from flask import Flask
from flask import render_template
from flask import Response, request, jsonify
app = Flask(__name__)
scoreboard = [
{
"id": 1,
"name": "Boston Bruins",
"score": 7
},
{
"id": 2,
"name": "Tampa Bay Lightning",
"score": 5
},
{
"id": 3,
"name": "Toronto Maple Leafs",
"score": 2
},
{
"id": 4,
"name": "Florida Panthers",
"score": 1
},
{
"id": 5,
"name": "Buffalo Sabres",
"score": 1
},
]
@app.route('/')
def show_scoreboard():
return render_template('scoreboard.html', scoreboard = scoreboard)
@app.route('/increase_score', methods=['GET', 'POST'])
def increase_score():
global scoreboard
json_data = request.get_json()
team_id = json_data["id"]
for team in scoreboard:
if team["id"] == team_id:
team["score"] += 1
return jsonify(scoreboard=scoreboard)
if __name__ == '__main__':
app.run(debug = True)