Skip to content

Commit

Permalink
Add helper properties to SR notes
Browse files Browse the repository at this point in the history
closes #127
  • Loading branch information
thesadru authored Jun 9, 2023
1 parent b5c9332 commit de6128a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion genshin/client/components/wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion genshin/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
6 changes: 3 additions & 3 deletions genshin/models/genshin/chronicle/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion genshin/models/starrail/chronicle/challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from .base import PartialTime

__all__ = ["StarRailFloor", "FloorNode", "StarRailChallenge"]
__all__ = ["FloorNode", "StarRailChallenge", "StarRailFloor"]


class FloorNode(APIModel):
Expand Down
5 changes: 5 additions & 0 deletions genshin/models/starrail/chronicle/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit de6128a

Please sign in to comment.