From dc7e5abf4ed703eea8c8b693a9579c96453d3338 Mon Sep 17 00:00:00 2001 From: Brad Brown Date: Wed, 22 Jun 2022 10:12:40 -0500 Subject: [PATCH] fix add user, add sync round users from gsheets --- pyproject.toml | 1 + wordlinator/app/__init__.py | 33 ++++++++++++++++++++++++++++++++- wordlinator/utils/__init__.py | 6 +++++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 4fac319..bfaa272 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,6 +39,7 @@ db-load = "wordlinator.app:load_db_scores" add-user = "wordlinator.app:sync_add_user" create-round = "wordlinator.app:create_round" copy-users = "wordlinator.app:copy_users" +gs-user-sync = "wordlinator.app:sync_gsheet_users" [tool.mypy] ignore_missing_imports = true diff --git a/wordlinator/app/__init__.py b/wordlinator/app/__init__.py index 817850e..c7763c9 100644 --- a/wordlinator/app/__init__.py +++ b/wordlinator/app/__init__.py @@ -270,9 +270,40 @@ def copy_users(): wordlinator.db.pg.WordleDb().copy_players_from_round(args.from_round, args.to_round) +async def pull_gsheets_users(round_no): + db = wordlinator.db.pg.WordleDb() + db_users = db.get_users_by_round(round_no=round_no) + + round = db.get_or_create_round(round_no) + wordle_day = wordlinator.utils.WordleDay.from_date(round.end_date) + + sheets = wordlinator.sheets.SheetsClient(wordle_day=wordle_day) + sheets_users = sheets.get_users() + + for user in sheets_users: + db_match = [u for u in db_users if u.username == user] + if not db_match: + rich.print(f"[yellow]Adding {user} to Round {round_no}") + await add_user(user, games=[round_no]) + + for user in db_users: + if user.username not in sheets_users: + rich.print(f"[yellow]Removing {user.username} from Round {round_no}") + db.remove_user_from_round(user.username, round_no) + + +def sync_gsheet_users(): + parser = argparse.ArgumentParser() + parser.add_argument("round_no", help="The round to sync.") + args = parser.parse_args() + asyncio.run(pull_gsheets_users(args.round_no)) + + def sync_add_user(): args = _add_user_args() - asyncio.run(add_user(args)) + asyncio.run( + add_user(args.username, args.games, args.unenroll_games, args.check_twitter) + ) def sync_main(): diff --git a/wordlinator/utils/__init__.py b/wordlinator/utils/__init__.py index 231eec3..b82286f 100644 --- a/wordlinator/utils/__init__.py +++ b/wordlinator/utils/__init__.py @@ -5,7 +5,11 @@ import typing WORDLE_DAY_ZERO = datetime.date(2021, 6, 19) -WORDLE_GOLF_ROUND_DATES = [datetime.date(2022, 5, 9), datetime.date(2022, 5, 31)] +WORDLE_GOLF_ROUND_DATES = [ + datetime.date(2022, 5, 9), + datetime.date(2022, 5, 31), + datetime.date(2022, 6, 24), +] def date_from_string(datestr: str):