Add main update func
This commit is contained in:
@@ -24,6 +24,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"
|
||||||
|
|
||||||
[tool.mypy]
|
[tool.mypy]
|
||||||
ignore_missing_imports = true
|
ignore_missing_imports = true
|
||||||
|
|||||||
@@ -26,6 +26,21 @@ async def get_scores(
|
|||||||
return 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):
|
async def main(wordle_day=None):
|
||||||
scores = await get_scores(wordle_day)
|
scores = await get_scores(wordle_day)
|
||||||
|
|
||||||
@@ -82,5 +97,10 @@ def sync_main():
|
|||||||
asyncio.run(main(wordle_day=wordle_day))
|
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__":
|
if __name__ == "__main__":
|
||||||
sync_main()
|
sync_main()
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class SheetsClient:
|
|||||||
)
|
)
|
||||||
return score_data
|
return score_data
|
||||||
|
|
||||||
def get_scores(self):
|
def get_scores(self, completed_only=True):
|
||||||
sheets = self.client.spreadsheets()
|
sheets = self.client.spreadsheets()
|
||||||
result = (
|
result = (
|
||||||
sheets.values()
|
sheets.values()
|
||||||
@@ -95,7 +95,7 @@ class SheetsClient:
|
|||||||
ranges = result.get("valueRanges", [])
|
ranges = result.get("valueRanges", [])
|
||||||
names = [row[0] for row in ranges[0].get("values", [])]
|
names = [row[0] for row in ranges[0].get("values", [])]
|
||||||
scores = ranges[1].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):
|
def write_scores(self, score_dict):
|
||||||
body = {"values": list(score_dict.values())}
|
body = {"values": list(score_dict.values())}
|
||||||
|
|||||||
Reference in New Issue
Block a user