diff --git a/kappa123/server/runs.py b/kappa123/server/runs.py index 40b7122..baadadf 100644 --- a/kappa123/server/runs.py +++ b/kappa123/server/runs.py @@ -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()