Skip to content

Commit

Permalink
Fix set secret logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ishefi committed Feb 7, 2024
1 parent c2795c7 commit 575b35c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion logic/game_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def get_secret(self) -> str | None:
async def set_secret(self, secret: str, clues: list[str]) -> None:
with hs_transaction(self.session, expire_on_commit=False) as session:
db_secret = tables.SecretWord(word=secret, game_date=self.date)
session.add(secret)
session.add(db_secret)
with hs_transaction(self.session) as session:
for clue in clues:
session.add(tables.HotClue(secret_word_id=db_secret.id, clue=clue))
Expand Down
18 changes: 11 additions & 7 deletions scripts/set_secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ async def main() -> None:
else:
secret = await get_random_word(model, args.top_sample)
while True:
await do_populate(
if await do_populate(
session, redis, secret, date, model, args.force, args.top_sample
)
if not args.iterative:
break
date += datetime.timedelta(days=1)
print(f"Now doing {date}")
):
if not args.iterative:
break
date += datetime.timedelta(days=1)
print(f"Now doing {date}")
secret = await get_random_word(model, args.top_sample)


Expand All @@ -121,7 +121,11 @@ async def do_populate(
top_sample: int | None,
) -> bool:
logic = CacheSecretLogic(session, redis, secret, dt=date, model=model)
await logic.simulate_set_secret(force=force)
try:
await logic.simulate_set_secret(force=force)
except ValueError as err:
print(err)
return False
cache = [w[::-1] for w in (await logic.cache)[::-1]]
print(" ,".join(cache))
print(cache[0])
Expand Down

0 comments on commit 575b35c

Please sign in to comment.