Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
lgc2333 committed Nov 11, 2024
1 parent 9674a26 commit 4ed3fd6
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions cooaki/akinator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
from contextlib import asynccontextmanager, suppress
from dataclasses import dataclass
from typing import Any, Dict, List, Optional, cast
from typing import Any, Dict, Optional

from cookit.pyd import type_validate_json
from httpx import AsyncClient, Cookies
Expand Down Expand Up @@ -169,15 +169,15 @@ async def start(self):
async with self.create_client() as cli:
resp_text = (await cli.post(url, data=data)).raise_for_status().text

session_match = re.search(r'name="session"\s+id="session"\s+value="([^"]+)"', resp_text)
if not session_match:
input_reg = r'name="{}"\s+id="{}"\s+value="(?P<value>.+?)"'

if not (session_m := re.search(input_reg.format("session"), resp_text)):
raise ValueError("Failed to find session")
session = session_match.group(1)
session: str = session_m["value"]

signature_match = re.search(r'name="signature"\s+id="signature"\s+value="([^"]+)"', resp_text)
if not signature_match:
if not (signature_m := re.search(input_reg.format("signature"), resp_text)):
raise ValueError("Failed to find signature")
signature = signature_match.group(1)
signature: str = signature_m["value"]

question_match = re.search(
(
Expand Down

0 comments on commit 4ed3fd6

Please sign in to comment.