From aa00260c17a62bb02c71ec850dd54a37a6f09ce7 Mon Sep 17 00:00:00 2001 From: Brad Brown Date: Sun, 5 Jun 2022 14:02:53 -0500 Subject: [PATCH] refresh wordle day in cache --- wordlinator/utils.py | 16 ++++++++++------ wordlinator/web/__init__.py | 19 +++++++++++++------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/wordlinator/utils.py b/wordlinator/utils.py index 04d1bd9..b83d9da 100644 --- a/wordlinator/utils.py +++ b/wordlinator/utils.py @@ -46,9 +46,13 @@ class WordleDay: # Designed so that "today" will be the current date in CST # Regardless of where the code is run -today = ( - datetime.datetime.now(datetime.timezone.utc) - .astimezone(datetime.timezone(datetime.timedelta(hours=-5), name="US Central")) - .date() -) -WORDLE_TODAY = WordleDay.from_date(today) +def get_wordle_today(): + today = ( + datetime.datetime.now(datetime.timezone.utc) + .astimezone(datetime.timezone(datetime.timedelta(hours=-5), name="US Central")) + .date() + ) + return WordleDay.from_date(today) + + +WORDLE_TODAY = get_wordle_today() diff --git a/wordlinator/web/__init__.py b/wordlinator/web/__init__.py index 86799b4..3acdc97 100644 --- a/wordlinator/web/__init__.py +++ b/wordlinator/web/__init__.py @@ -27,9 +27,19 @@ long_callback_manager = dash.long_callback.DiskcacheLongCallbackManager( ) +@functools.lru_cache() +def _wordle_today(ttl_hash=None): + return wordlinator.utils.get_wordle_today() + + +def wordle_today(): + return _wordle_today(get_ttl_hash()) + + @functools.lru_cache() def _scores_from_db(ttl_hash=None): - return db.WordleDb().get_scores(wordlinator.utils.WORDLE_TODAY.golf_hole.game_no) + wordle_day = wordle_today() + return db.WordleDb().get_scores(wordle_day.golf_hole.game_no) def scores_from_db(): @@ -107,7 +117,7 @@ def get_scores(): hole_columns = [ {"name": f"Hole {i}", "id": f"Hole {i}", "type": "numeric"} - for i in range(1, wordlinator.utils.WORDLE_TODAY.golf_hole.hole_no + 1) + for i in range(1, wordle_today().golf_hole.hole_no + 1) ] columns = [ {"name": "Name", "id": "Name", "type": "text"}, @@ -202,10 +212,7 @@ def get_daily_stats(): {"name": n, "id": n} for n in ( "Score", - *[ - f"{i}" - for i in range(1, wordlinator.utils.WORDLE_TODAY.golf_hole.hole_no + 1) - ], + *[f"{i}" for i in range(1, wordle_today().golf_hole.hole_no + 1)], ) ] return dash.dash_table.DataTable(