Update start date and add user check
This commit is contained in:
@@ -25,6 +25,7 @@ ipython = "^8.4.0"
|
|||||||
[tool.poetry.scripts]
|
[tool.poetry.scripts]
|
||||||
wordlinator = "wordlinator.app:sync_main"
|
wordlinator = "wordlinator.app:sync_main"
|
||||||
update = "wordlinator.app:sync_update"
|
update = "wordlinator.app:sync_update"
|
||||||
|
show-user = "wordlinator.app:sync_show_user"
|
||||||
|
|
||||||
[tool.mypy]
|
[tool.mypy]
|
||||||
ignore_missing_imports = true
|
ignore_missing_imports = true
|
||||||
|
|||||||
@@ -26,30 +26,13 @@ async def get_scores(
|
|||||||
return scores
|
return scores
|
||||||
|
|
||||||
|
|
||||||
async def main_update(
|
def print_score_table(wordle_day, scores):
|
||||||
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)
|
|
||||||
|
|
||||||
table = rich.table.Table(
|
table = rich.table.Table(
|
||||||
rich.table.Column(header="Username", style="green"),
|
rich.table.Column(header="Username", style="green"),
|
||||||
rich.table.Column("Raw Score"),
|
rich.table.Column("Raw Score"),
|
||||||
rich.table.Column("Golf Score"),
|
rich.table.Column("Golf Score"),
|
||||||
rich.table.Column("Score Name"),
|
rich.table.Column("Score Name"),
|
||||||
title=f"Wordle Scores Day {wordle_day}",
|
title=f"Wordle Scores Day {wordle_day.wordle_no}",
|
||||||
)
|
)
|
||||||
for username, score in scores.items():
|
for username, score in scores.items():
|
||||||
args = [username]
|
args = [username]
|
||||||
@@ -72,6 +55,30 @@ async def main(wordle_day=None):
|
|||||||
rich.print(table)
|
rich.print(table)
|
||||||
|
|
||||||
|
|
||||||
|
async def main_update(
|
||||||
|
wordle_day: wordlinator.utils.WordleDay = wordlinator.utils.WORDLE_TODAY,
|
||||||
|
):
|
||||||
|
sheets_client = wordlinator.sheets.SheetsClient(wordle_day=wordle_day)
|
||||||
|
|
||||||
|
today_scores = await get_scores(wordle_day=wordle_day)
|
||||||
|
|
||||||
|
sheets_client.update_scores(today_scores)
|
||||||
|
|
||||||
|
print_score_table(wordle_day, today_scores)
|
||||||
|
|
||||||
|
|
||||||
|
async def main(wordle_day=wordlinator.utils.WORDLE_TODAY):
|
||||||
|
rich.print(wordle_day)
|
||||||
|
scores = await get_scores(wordle_day)
|
||||||
|
print_score_table(wordle_day, scores)
|
||||||
|
|
||||||
|
|
||||||
|
async def show_user(username: str):
|
||||||
|
client = wordlinator.twitter.TwitterClient()
|
||||||
|
scores = await client.get_user_wordles(username)
|
||||||
|
rich.print(scores)
|
||||||
|
|
||||||
|
|
||||||
def _get_day():
|
def _get_day():
|
||||||
parser = argparse.ArgumentParser("wordlinator")
|
parser = argparse.ArgumentParser("wordlinator")
|
||||||
days = parser.add_mutually_exclusive_group()
|
days = parser.add_mutually_exclusive_group()
|
||||||
@@ -102,5 +109,12 @@ def sync_update():
|
|||||||
asyncio.run(main_update(wordle_day=wordle_day))
|
asyncio.run(main_update(wordle_day=wordle_day))
|
||||||
|
|
||||||
|
|
||||||
|
def sync_show_user():
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("username")
|
||||||
|
args = parser.parse_args()
|
||||||
|
asyncio.run(show_user(args.username))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sync_main()
|
sync_main()
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import rich.table
|
|||||||
import wordlinator.utils
|
import wordlinator.utils
|
||||||
|
|
||||||
SPREADSHEET_ID = "1POoklzvD643pvdMAleFxrecN50IMv2NdQBs9h43Hw8E"
|
SPREADSHEET_ID = "1POoklzvD643pvdMAleFxrecN50IMv2NdQBs9h43Hw8E"
|
||||||
SHEET_NAME = os.getenv("SHEET_NAME", "AutoTest")
|
SHEET_NAME = os.getenv("SHEET_NAME", None)
|
||||||
USER_RANGE = "A2:A1000"
|
USER_RANGE = "A2:A1000"
|
||||||
SCORE_RANGE = "C2:T1000"
|
SCORE_RANGE = "C2:T1000"
|
||||||
|
|
||||||
@@ -45,6 +45,8 @@ class SheetsClient:
|
|||||||
self.game_round = None
|
self.game_round = None
|
||||||
else:
|
else:
|
||||||
self.game_round = wordle_day.golf_hole.hole_no
|
self.game_round = wordle_day.golf_hole.hole_no
|
||||||
|
if not self.sheet_name:
|
||||||
|
self.sheet_name = f"Round {wordle_day.golf_hole.game_no}"
|
||||||
|
|
||||||
def _get_sheet_values(self, range):
|
def _get_sheet_values(self, range):
|
||||||
sheets = self.client.spreadsheets()
|
sheets = self.client.spreadsheets()
|
||||||
@@ -112,6 +114,26 @@ class SheetsClient:
|
|||||||
)
|
)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def update_scores(self, day_scores_dict):
|
||||||
|
if self.game_round is None:
|
||||||
|
raise ValueError("Cannot update scores if not in a game round")
|
||||||
|
current_scores = self.get_scores()
|
||||||
|
for name, score in day_scores_dict.items():
|
||||||
|
current_row = current_scores[name]
|
||||||
|
row_len = len(current_row)
|
||||||
|
score_val = str(score.raw_score) if score else ""
|
||||||
|
if row_len == (self.game_round - 1):
|
||||||
|
# If the row doesn't include today yet, add it.
|
||||||
|
current_row.append(score_val)
|
||||||
|
elif row_len >= self.game_round:
|
||||||
|
# If there's already an entry for today's game,
|
||||||
|
# only update if the value is empty.
|
||||||
|
day_idx = self.game_round - 1
|
||||||
|
if current_row[day_idx] == "":
|
||||||
|
current_row[day_idx] = score_val
|
||||||
|
current_scores[name] = current_row
|
||||||
|
self.write_scores(current_scores)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
scores = SheetsClient().get_scores()
|
scores = SheetsClient().get_scores()
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import typing
|
|||||||
|
|
||||||
WORDLE_DAY_ZERO = datetime.date(2021, 6, 19)
|
WORDLE_DAY_ZERO = datetime.date(2021, 6, 19)
|
||||||
|
|
||||||
WORDLE_GOLF_ROUND_DATES = [datetime.date(2022, 5, 9), datetime.date(2022, 5, 30)]
|
WORDLE_GOLF_ROUND_DATES = [datetime.date(2022, 5, 9), datetime.date(2022, 5, 31)]
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
|
|||||||
Reference in New Issue
Block a user