mirror of
https://github.com/Xevion/trivia.git
synced 2025-12-09 16:08:54 -06:00
change refresh route to 'scores', implement app.logger statements instead of print
This commit is contained in:
@@ -11,9 +11,9 @@ from flask import request, make_response
|
||||
from trivia import app
|
||||
|
||||
|
||||
@app.route("/api/refresh")
|
||||
@app.route("/api/refresh/")
|
||||
def refresh():
|
||||
@app.route("/api/scores")
|
||||
@app.route("/api/scores/")
|
||||
def scores():
|
||||
"""
|
||||
Used for refreshing client-side table data. Returns a JSON response with all data necessary to build the table.
|
||||
"""
|
||||
@@ -22,8 +22,8 @@ def refresh():
|
||||
# Create response using namedtuples
|
||||
r = make_response(json.dumps([team._asdict() for team in teams]))
|
||||
r.mimetype = 'application/json'
|
||||
|
||||
status_code = 200
|
||||
|
||||
# Try to handle If-Modified-Since header properly (304 Not Modified
|
||||
try:
|
||||
if request.headers['If-Modified-Since']:
|
||||
@@ -34,6 +34,6 @@ def refresh():
|
||||
except KeyError:
|
||||
pass # Header was not supplied. Ignore.
|
||||
except ValueError:
|
||||
print('If-Modified-Since Header could not be parsed.') # Header could not be parsed.
|
||||
app.logger.warning('If-Modified-Since Header could not be parsed.') # Header could not be parsed.
|
||||
|
||||
return r, status_code
|
||||
|
||||
@@ -7,7 +7,7 @@ import json
|
||||
import os
|
||||
from typing import List
|
||||
|
||||
from trivia import Team
|
||||
from trivia import Team, app
|
||||
|
||||
# Generate paths
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
@@ -41,7 +41,7 @@ def refreshScores() -> None:
|
||||
# Update tracking var
|
||||
lastChange = curChange
|
||||
|
||||
print('Attempting to load and parse scores file.')
|
||||
app.logger.debug('Attempting to load and parse scores file.')
|
||||
with open(SCORES_FILE) as file:
|
||||
temp = json.load(file)
|
||||
|
||||
@@ -53,11 +53,11 @@ def refreshScores() -> None:
|
||||
scores=team['scores']
|
||||
) for team in temp
|
||||
]
|
||||
print(f'Successfully loaded ({len(temp)} teams).')
|
||||
app.logger.debug(f'Successfully loaded ({len(temp)} teams).')
|
||||
|
||||
global teams
|
||||
teams = temp
|
||||
|
||||
# If invalid or inaccessible, simply do nothing.
|
||||
except json.JSONDecodeError:
|
||||
print('Scores file could not be opened or parsed.')
|
||||
app.logger.error('Scores file could not be opened or parsed.', print_exc=True)
|
||||
|
||||
Reference in New Issue
Block a user