Handle case when tracker is down and flask lacks cache.
parent
4dad65bd90
commit
5eefb6fa67
|
@ -9,9 +9,12 @@ import logging
|
|||
|
||||
CACHE_AGE_MAX = 600
|
||||
CACHE_LOCATION='/tmp/runs.json'
|
||||
TRACKER_URL='https://gamesdonequick.com/tracker/search/?type=run&event=20'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class KappaException(Exception):
|
||||
pass
|
||||
class GDQException(Exception):
|
||||
pass
|
||||
|
||||
|
@ -38,15 +41,18 @@ def fetch_or_cache_runs():
|
|||
|
||||
|
||||
def load_run_cache():
|
||||
with open(CACHE_LOCATION, 'r') as f:
|
||||
string = f.read()
|
||||
return json.loads(string)
|
||||
if os.path.isfile(CACHE_LOCATION):
|
||||
with open(CACHE_LOCATION, 'r') as f:
|
||||
string = f.read()
|
||||
return json.loads(string)
|
||||
else:
|
||||
raise KappaException("GDQ Tracker Appears to be down, and I don't have a saved copy. Try again later.")
|
||||
|
||||
|
||||
def fetch_runs():
|
||||
try:
|
||||
logger.warn("Re-fetching cache")
|
||||
r = requests.get('https://gamesdonequick.com/tracker/search/?type=run&event=20', timeout=3)
|
||||
r = requests.get(TRACKER_URL, timeout=3)
|
||||
if r.status_code != 200:
|
||||
raise GDQException("GDQ not returning 200")
|
||||
output = r.json()
|
||||
|
|
Loading…
Reference in New Issue