From 70b683268bb2330d4fd5d7e2006e65d0270e7dbb Mon Sep 17 00:00:00 2001 From: omg-xtao <100690902+omg-xtao@users.noreply.github.com> Date: Mon, 17 Jul 2023 13:14:40 +0800 Subject: [PATCH] :bug: Fix some genshin problems --- simnet/client/components/transaction.py | 2 +- simnet/client/cookies.py | 1 + simnet/client/routes.py | 4 ++-- simnet/models/genshin/chronicle/notes.py | 27 ++++-------------------- simnet/models/genshin/transaction.py | 7 +++--- 5 files changed, 11 insertions(+), 30 deletions(-) diff --git a/simnet/client/components/transaction.py b/simnet/client/components/transaction.py index a166a40..4023b2b 100644 --- a/simnet/client/components/transaction.py +++ b/simnet/client/components/transaction.py @@ -57,7 +57,7 @@ class TransactionClient(BaseClient): lang (str, optional): The language to use for the request. Defaults to None. """ kind = TransactionKind(kind) - endpoint = "get" + kind.value.capitalize() + "Log" + endpoint = "Get" + kind.value.capitalize() + "Log" data = await self.request_transaction( endpoint, diff --git a/simnet/client/cookies.py b/simnet/client/cookies.py index 0be425d..cccf3fc 100644 --- a/simnet/client/cookies.py +++ b/simnet/client/cookies.py @@ -30,6 +30,7 @@ class Cookies(_Cookies): for cookie in cookies.jar: self.jar.set_cookie(cookie) elif isinstance(cookies, str): + self.jar = CookieJar() cookie = SimpleCookie(cookies) for key, value in cookie.items(): self.set(key, value.value) diff --git a/simnet/client/routes.py b/simnet/client/routes.py index e3c5167..a54f1e0 100644 --- a/simnet/client/routes.py +++ b/simnet/client/routes.py @@ -273,8 +273,8 @@ INFO_LEDGER_URL = GameRoute( ) YSULOG_URL = InternationalRoute( - overseas="https://hk4e-api-os.hoyoverse.com/ysulog/api/", - chinese="https://hk4e-api.mihoyo.com/ysulog/api/", + overseas="https://hk4e-api-os.hoyoverse.com/common/hk4e_self_help_query/User/", + chinese="https://hk4e-api.mihoyo.com/common/hk4e_self_help_query/User/", ) HK4E_URL = Route("https://sg-hk4e-api.hoyoverse.com/common/hk4e_global/") diff --git a/simnet/models/genshin/chronicle/notes.py b/simnet/models/genshin/chronicle/notes.py index 3cce32c..587c3d1 100644 --- a/simnet/models/genshin/chronicle/notes.py +++ b/simnet/models/genshin/chronicle/notes.py @@ -1,12 +1,11 @@ from datetime import timedelta, datetime from typing import Union, Literal, Tuple, List, Optional, Dict, Any -from pydantic import Field, root_validator, validator +from pydantic import Field, root_validator from simnet.models.base import APIModel -from simnet.models.genshin.character import BaseCharacter -__all__ = ("Expedition", "ExpeditionCharacter", "Notes") +__all__ = ("Expedition", "Notes") def _process_timedelta(time: Union[int, timedelta, datetime]) -> datetime: @@ -36,20 +35,16 @@ def _process_timedelta(time: Union[int, timedelta, datetime]) -> datetime: return time -class ExpeditionCharacter(BaseCharacter): - """Expedition character.""" - - class Expedition(APIModel): """The model for a real-time expedition. Attributes: - character (ExpeditionCharacter): The expedition character. + character (str): The expedition character icon url. status (Literal["Ongoing", "Finished"]): The status of the expedition. remaining_time (timedelta): The remaining time of the expedition. """ - character: ExpeditionCharacter = Field(alias="avatar_side_icon") + character: str = Field(alias="avatar_side_icon") status: Literal["Ongoing", "Finished"] remaining_time: timedelta = Field(alias="remained_time") @@ -63,20 +58,6 @@ class Expedition(APIModel): """A property that returns the completion time of the expedition.""" return datetime.now().astimezone() + self.remaining_time - @validator("character", pre=True) - def complete_character(cls, v: Any) -> Any: - """A validator that completes the expedition character information. - - Args: - v (Any): The input character information. - - Returns: - Any: The completed character information. - """ - if isinstance(v, str): - return dict(icon=v) # type: ignore - return v - class TransformerTimedelta(timedelta): """The model for a transformer recovery time.""" diff --git a/simnet/models/genshin/transaction.py b/simnet/models/genshin/transaction.py index 52f8cab..9c74e21 100644 --- a/simnet/models/genshin/transaction.py +++ b/simnet/models/genshin/transaction.py @@ -33,10 +33,9 @@ class BaseTransaction(APIModel): kind: TransactionKind id: int - uid: int - time: datetime + time: datetime = Field(alias="datetime") amount: int = Field(alias="add_num") - reason_id: int = Field(alias="reason") + reason: str class Transaction(BaseTransaction): @@ -51,4 +50,4 @@ class ItemTransaction(BaseTransaction): kind: Literal[TransactionKind.ARTIFACT, TransactionKind.WEAPON] name: str - rarity: int = Field(alias="rank") + rarity: int = Field(alias="quality")