mirror of
https://github.com/Xevion/trivia.git
synced 2025-12-14 02:13:25 -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
|
from trivia import app
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api/refresh")
|
@app.route("/api/scores")
|
||||||
@app.route("/api/refresh/")
|
@app.route("/api/scores/")
|
||||||
def refresh():
|
def scores():
|
||||||
"""
|
"""
|
||||||
Used for refreshing client-side table data. Returns a JSON response with all data necessary to build the table.
|
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
|
# Create response using namedtuples
|
||||||
r = make_response(json.dumps([team._asdict() for team in teams]))
|
r = make_response(json.dumps([team._asdict() for team in teams]))
|
||||||
r.mimetype = 'application/json'
|
r.mimetype = 'application/json'
|
||||||
|
|
||||||
status_code = 200
|
status_code = 200
|
||||||
|
|
||||||
# Try to handle If-Modified-Since header properly (304 Not Modified
|
# Try to handle If-Modified-Since header properly (304 Not Modified
|
||||||
try:
|
try:
|
||||||
if request.headers['If-Modified-Since']:
|
if request.headers['If-Modified-Since']:
|
||||||
@@ -34,6 +34,6 @@ def refresh():
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
pass # Header was not supplied. Ignore.
|
pass # Header was not supplied. Ignore.
|
||||||
except ValueError:
|
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
|
return r, status_code
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from trivia import Team
|
from trivia import Team, app
|
||||||
|
|
||||||
# Generate paths
|
# Generate paths
|
||||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
@@ -41,7 +41,7 @@ def refreshScores() -> None:
|
|||||||
# Update tracking var
|
# Update tracking var
|
||||||
lastChange = curChange
|
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:
|
with open(SCORES_FILE) as file:
|
||||||
temp = json.load(file)
|
temp = json.load(file)
|
||||||
|
|
||||||
@@ -53,11 +53,11 @@ def refreshScores() -> None:
|
|||||||
scores=team['scores']
|
scores=team['scores']
|
||||||
) for team in temp
|
) for team in temp
|
||||||
]
|
]
|
||||||
print(f'Successfully loaded ({len(temp)} teams).')
|
app.logger.debug(f'Successfully loaded ({len(temp)} teams).')
|
||||||
|
|
||||||
global teams
|
global teams
|
||||||
teams = temp
|
teams = temp
|
||||||
|
|
||||||
# If invalid or inaccessible, simply do nothing.
|
# If invalid or inaccessible, simply do nothing.
|
||||||
except json.JSONDecodeError:
|
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