From de6128a7fa859cacc38f572e790484a64835e836 Mon Sep 17 00:00:00 2001 From: ashlen Date: Fri, 9 Jun 2023 15:31:12 +0000 Subject: [PATCH] Add helper properties to SR notes closes #127 --- genshin/client/components/wiki.py | 3 ++- genshin/errors.py | 2 +- genshin/models/genshin/chronicle/notes.py | 6 +++--- genshin/models/starrail/chronicle/challenge.py | 2 +- genshin/models/starrail/chronicle/notes.py | 5 +++++ 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/genshin/client/components/wiki.py b/genshin/client/components/wiki.py index b33316a9..fbe1bb9c 100644 --- a/genshin/client/components/wiki.py +++ b/genshin/client/components/wiki.py @@ -99,7 +99,8 @@ async def get_wiki_page( cache_key = cache.cache_key("wiki", endpoint="page", id=id, lang=lang or self.lang) data = await self.request_wiki("entry_page", lang=lang, params=params, static_cache=cache_key) - return models.WikiPage(**data["page"]) + data["page"].pop("lang", "") # always an empty string + return models.WikiPage(**data["page"], lang=lang or self.lang) async def get_wiki_pages( self, diff --git a/genshin/errors.py b/genshin/errors.py index 9ea45594..7a232670 100644 --- a/genshin/errors.py +++ b/genshin/errors.py @@ -255,7 +255,7 @@ def raise_for_retcode(data: typing.Dict[str, typing.Any]) -> typing.NoReturn: def check_for_geetest(data: typing.Dict[str, typing.Any]) -> None: """Check if geetest was triggered and raise an error.""" - if not data.get("data") or data["data"].get("gt_result"): + if not data.get("data") or not data["data"].get("gt_result"): return gt_result = data["data"]["gt_result"] diff --git a/genshin/models/genshin/chronicle/notes.py b/genshin/models/genshin/chronicle/notes.py index 07b08271..89d23b07 100644 --- a/genshin/models/genshin/chronicle/notes.py +++ b/genshin/models/genshin/chronicle/notes.py @@ -104,17 +104,17 @@ class Notes(APIModel): @property def resin_recovery_time(self) -> datetime.datetime: - """The remaining time until resin recovery in seconds.""" + """The time when resin will be recovered.""" return datetime.datetime.now().astimezone() + self.remaining_resin_recovery_time @property def realm_currency_recovery_time(self) -> datetime.datetime: - """The remaining time until realm currency recovery in seconds.""" + """The time when realm currency will be recovered.""" return datetime.datetime.now().astimezone() + self.remaining_realm_currency_recovery_time @property def transformer_recovery_time(self) -> typing.Optional[datetime.datetime]: - """The remaining time until realm currency recovery in seconds.""" + """The time the transformer will be recovered.""" if self.remaining_transformer_recovery_time is None: return None diff --git a/genshin/models/starrail/chronicle/challenge.py b/genshin/models/starrail/chronicle/challenge.py index f5365b05..18510312 100644 --- a/genshin/models/starrail/chronicle/challenge.py +++ b/genshin/models/starrail/chronicle/challenge.py @@ -6,7 +6,7 @@ from .base import PartialTime -__all__ = ["StarRailFloor", "FloorNode", "StarRailChallenge"] +__all__ = ["FloorNode", "StarRailChallenge", "StarRailFloor"] class FloorNode(APIModel): diff --git a/genshin/models/starrail/chronicle/notes.py b/genshin/models/starrail/chronicle/notes.py index 190e1cac..b6d2350c 100644 --- a/genshin/models/starrail/chronicle/notes.py +++ b/genshin/models/starrail/chronicle/notes.py @@ -34,3 +34,8 @@ class StarRailNote(APIModel): accepted_epedition_num: int total_expedition_num: int expeditions: typing.Sequence[StarRailExpedition] + + @property + def stamina_recovery_time(self) -> datetime.datetime: + """The time when stamina will be recovered.""" + return datetime.datetime.now().astimezone() + self.stamina_recover_time