From febad804ee09334d7a95d64b2bcc65f41163ddab Mon Sep 17 00:00:00 2001 From: Brad Brown Date: Sat, 28 May 2022 14:27:22 -0500 Subject: [PATCH] Add main update func --- pyproject.toml | 1 + wordlinator/app/__init__.py | 20 ++++++++++++++++++++ wordlinator/sheets/__init__.py | 4 ++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 45fcb45..0fc53be 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,6 +24,7 @@ ipython = "^8.4.0" [tool.poetry.scripts] wordlinator = "wordlinator.app:sync_main" +update = "wordlinator.app:sync_update" [tool.mypy] ignore_missing_imports = true diff --git a/wordlinator/app/__init__.py b/wordlinator/app/__init__.py index 3669853..635c9e1 100644 --- a/wordlinator/app/__init__.py +++ b/wordlinator/app/__init__.py @@ -26,6 +26,21 @@ async def get_scores( return scores +async def main_update( + wordle_day: wordlinator.utils.WordleDay = wordlinator.utils.WORDLE_TODAY, +): + sheets_client = wordlinator.sheets.SheetsClient(wordle_day=wordle_day) + sheet_scores = sheets_client.get_scores(completed_only=False) + + today_scores = await get_scores(wordle_day=wordle_day) + + for user, score in today_scores.items(): + if score and sheet_scores[user][-1] != score: + sheet_scores[user][-1] = score + + sheets_client.write_scores(sheet_scores) + + async def main(wordle_day=None): scores = await get_scores(wordle_day) @@ -82,5 +97,10 @@ def sync_main(): asyncio.run(main(wordle_day=wordle_day)) +def sync_update(): + wordle_day = _get_day() + asyncio.run(main_update(wordle_day=wordle_day)) + + if __name__ == "__main__": sync_main() diff --git a/wordlinator/sheets/__init__.py b/wordlinator/sheets/__init__.py index 7a0d82b..57a275b 100644 --- a/wordlinator/sheets/__init__.py +++ b/wordlinator/sheets/__init__.py @@ -79,7 +79,7 @@ class SheetsClient: ) return score_data - def get_scores(self): + def get_scores(self, completed_only=True): sheets = self.client.spreadsheets() result = ( sheets.values() @@ -95,7 +95,7 @@ class SheetsClient: ranges = result.get("valueRanges", []) names = [row[0] for row in ranges[0].get("values", [])] scores = ranges[1].get("values", []) - return self.score_dict(names, scores) + return self.score_dict(names, scores, completed_only=completed_only) def write_scores(self, score_dict): body = {"values": list(score_dict.values())}