Card data reading ok

This commit is contained in:
Pascal P. 2026-08-06 22:02:43 +02:00
parent c02f08a767
commit 3ef295339a
2 changed files with 50 additions and 6 deletions

View File

@ -54,9 +54,11 @@ class App:
packs_last_regen_at = d.packs_last_regen_at
if packs_remaining == 10:
packs_remaining, packs_last_regen_at = wm_client.open_pack(
packs_remaining, packs_last_regen_at, cards = wm_client.open_pack(
user.auth_cookies
)
for card in cards:
logger.info("Pulled [{}] {} (uid={})", card.rarity, card.name, card._id)
# Does this math still works when we are opening the 9th pack ?
next_pack_in = WikiMastersClient.ONE_PACK_TIME - (

View File

@ -6,11 +6,47 @@ from loguru import logger
from datetime import datetime, timedelta
from ..lib.supabase_cookie import get_auth_cookies
from typing import Self
from enum import StrEnum
# supabase ?
# https://cyrxjeppjqsxxjayfrur.supabase.co/auth/v1/token?grant_type=password
# https://cyrxjeppjqsxxjayfrur.supabase.co/auth/v1/user
# https://cyrxjeppjqsxxjayfrur.supabase.co/rest/v1/rpc/sync_profile_packs
# POST /api/user-cards/${r.id}/discard
class Rarity(StrEnum):
Common = "C"
LessCommon = "PC"
Rare = "R"
SuperRare = "SR"
UltraRare = "UR"
Legendary = "L"
@dataclass
class CardDataSubset:
_id: str
name: str
summary: str | None
url: str
image_url: str | None
category: str | None
views: int
rarity: Rarity
@staticmethod
def from_json(d: dict) -> Self:
return CardDataSubset(
d["id"],
d["wikipedia_title"],
d["summary"],
d["wikipedia_url"],
d["image_url"],
d["category"],
d["pageviews"],
Rarity(d["rarity"]),
)
@dataclass
@ -50,6 +86,10 @@ class UserSession:
return SyncDataSubset.from_json(response.data[0])
def pull(self) -> tuple[int, str, list[CardDataSubset]]:
client = WikiMastersClient()
return client.open_pack(self.auth_cookies)
class WikiMastersClient:
BASE_URL = "https://www.wiki-masters.com"
@ -62,12 +102,11 @@ class WikiMastersClient:
def __init__(self) -> None:
self.logger = logger.bind(service=self.__class__.__name__)
self.users: dict[str, UserSession] = {}
def open_pack(self, cookies) -> tuple[int, str]:
def open_pack(self, cookies) -> tuple[int, str, list[CardDataSubset]]:
url = f"{self.BASE_URL}/api/packs/open"
logger.debug("trying to request a pull (cookies:{})", cookies)
logger.debug("trying to request a pull")
response = httpx.post(
url,
headers={"referer": f"{self.BASE_URL}/pulls"},
@ -81,9 +120,12 @@ class WikiMastersClient:
raise Exception("Could not pull :'(")
pull_data = response.json()
logger.debug("trying to pull: {}", pull_data)
return (pull_data["packs_remaining"], datetime.fromisoformat(pull_data["packs_last_regen_at"]))
return (
pull_data["packs_remaining"],
datetime.fromisoformat(pull_data["packs_last_regen_at"]),
[CardDataSubset.from_json(c) for c in pull_data["cards"]],
)
def login(self, email, password) -> UserSession:
sb_client = create_client(self.SUPABASE_URL, self.SUPABASE_KEY)