diff --git a/server.py b/server.py index 372a266c..dff55c3b 100644 --- a/server.py +++ b/server.py @@ -1,37 +1,37 @@ from flask import Flask from flask import render_template -from flask import Response, request, jsonify +from flask import request, jsonify app = Flask(__name__) scoreboard = [ { - "id": 1, - "name": "Boston Bruins", - "score": 7 + "id": 1, + "name": "Boston Bruins", + "score": 7 }, { - "id": 2, - "name": "Tampa Bay Lightning", - "score": 5 + "id": 2, + "name": "Tampa Bay Lightning", + "score": 5 }, { - "id": 3, - "name": "Toronto Maple Leafs", - "score": 2 + "id": 3, + "name": "Toronto Maple Leafs", + "score": 2 }, { - "id": 4, - "name": "Florida Panthers", - "score": 1 + "id": 4, + "name": "Florida Panthers", + "score": 1 }, { - "id": 5, - "name": "Buffalo Sabres", - "score": 1 + "id": 5, + "name": "Buffalo Sabres", + "score": 1 }, ] @@ -40,6 +40,7 @@ def show_scoreboard(): return render_template('scoreboard.html', scoreboard = scoreboard) + @app.route('/increase_score', methods=['GET', 'POST']) def increase_score(): global scoreboard @@ -50,7 +51,7 @@ def increase_score(): for team in scoreboard: if team["id"] == team_id: team["score"] += 1 - + scoreboard = sorted(scoreboard, key=lambda team_data: team_data["score"], reverse=True) return jsonify(scoreboard=scoreboard) diff --git a/static/scoreboard.js b/static/scoreboard.js index 34ce2009..f48d7c1c 100644 --- a/static/scoreboard.js +++ b/static/scoreboard.js @@ -32,7 +32,7 @@ function increase_score(id){ contentType: "application/json; charset=utf-8", data : JSON.stringify(team_id), success: function(result){ - + display_scoreboard(result.scoreboard); }, error: function(request, status, error){ console.log("Error");