diff --git a/common/tables.py b/common/tables.py index 3f42215..e1755d3 100644 --- a/common/tables.py +++ b/common/tables.py @@ -46,7 +46,7 @@ class UserHistory(SQLModel, table=True): id: int = Field(default=None, primary_key=True) user_id: int = Field(foreign_key="user.id", index=True) guess: str = HebrewString(32) - similarity: float | None + similarity: float distance: int egg: str | None = NoFinalHebrewString(default=None) game_date: datetime.date diff --git a/logic/game_logic.py b/logic/game_logic.py index 5e09def..9028034 100644 --- a/logic/game_logic.py +++ b/logic/game_logic.py @@ -108,10 +108,10 @@ async def get_secret_vector(self) -> np_float_arr: self._secret_cache[self.date] = vector return self._secret_cache[self.date] - async def get_similarity(self, word: str) -> float | None: + async def get_similarity(self, word: str) -> float: word_vector = await self.get_vector(word) if word_vector is None: - return None + raise HSError("Word not found", code=100796) secret_vector = await self.get_secret_vector() return await self.calc_similarity(secret_vector, word_vector) diff --git a/routers/game_routes.py b/routers/game_routes.py index 6af5471..99fb6a7 100644 --- a/routers/game_routes.py +++ b/routers/game_routes.py @@ -22,7 +22,7 @@ async def distance( request: Request, word: str = Query(default=..., min_length=2, max_length=24, regex=r"^[א-ת ']+$"), -) -> schemas.DistanceResponse | list[schemas.DistanceResponse]: +) -> list[schemas.DistanceResponse]: word = word.replace("'", "") if egg := EasterEggLogic.get_easter_egg(word): response = schemas.DistanceResponse( @@ -42,17 +42,15 @@ async def distance( distance=cache_score, solver_count=solver_count, ) - if request.headers.get("x-sh-version", "2022-02-20") >= "2023-09-10": - if request.state.user: - history_logic = UserHistoryLogic( - request.app.state.session, - request.state.user, - get_date(request.app.state.days_delta), - ) - return await history_logic.update_and_get_history(response) - else: - return [response] - return response + if request.state.user: + history_logic = UserHistoryLogic( + request.app.state.session, + request.state.user, + get_date(request.app.state.days_delta), + ) + return await history_logic.update_and_get_history(response) + else: + return [response] @game_router.get("/api/clue") diff --git a/scripts/semantle.py b/scripts/semantle.py index 9d7d4e7..74a4d09 100644 --- a/scripts/semantle.py +++ b/scripts/semantle.py @@ -3,6 +3,8 @@ import sys from datetime import datetime +from common.error import HSError + base = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) sys.path.extend([base]) @@ -33,8 +35,9 @@ async def main() -> None: ) inp = input(">") print(inp[::-1]) - similarity = await logic.get_similarity(inp) - if similarity is None or similarity < 0: + try: + similarity = await logic.get_similarity(inp) + except HSError: print("I don't know this word!") else: cache_score = await cache_logic.get_cache_score(inp)