Skip to content

Commit

Permalink
Fix HSR pure fiction time data
Browse files Browse the repository at this point in the history
  • Loading branch information
KT-Yeh committed Feb 7, 2024
1 parent e1e68d3 commit 3b08bf7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
13 changes: 13 additions & 0 deletions genshin/client/components/chronicle/starrail.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,17 @@ async def get_starrail_pure_fiction(
"""Get starrail pure fiction runs."""
payload = dict(schedule_type=2 if previous else 1, need_all="true")
data = await self._request_starrail_record("challenge_story", uid, lang=lang, payload=payload)

# In "groups", it contains time data from both the current season and previous season.
data = dict(data)
time = data["groups"][0]
if previous is True and len(data["groups"]) > 1:
time = data["groups"][1]

# Extract the time data.
data["schedule_id"] = time["schedule_id"]
data["begin_time"] = time["begin_time"]
data["end_time"] = time["end_time"]
data["name_mi18n"] = time["name_mi18n"]

return models.StarRailPureFiction(**data)
27 changes: 3 additions & 24 deletions genshin/models/starrail/chronicle/challenge.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
"""Starrail chronicle challenge."""

from typing import TYPE_CHECKING, Any, Dict, List, Optional

if TYPE_CHECKING:
import pydantic.v1 as pydantic
else:
try:
import pydantic.v1 as pydantic
except ImportError:
import pydantic
from typing import List, Optional

from genshin.models.model import Aliased, APIModel
from genshin.models.starrail.character import FloorCharacter
Expand Down Expand Up @@ -94,11 +86,10 @@ def score(self) -> int:

class StarRailPureFiction(APIModel):
"""Pure Fiction challenge in a season."""

name: str
season_id: int
season_id: int = Aliased("schedule_id")
begin_time: PartialTime
end_time: PartialTime
name: str = Aliased("name_mi18n")

total_stars: int = Aliased("star_num")
max_floor: str
Expand All @@ -107,15 +98,3 @@ class StarRailPureFiction(APIModel):

floors: List[FictionFloor] = Aliased("all_floor_detail")
max_floor_id: int

@pydantic.root_validator(pre=True)
def __unnest_groups(cls, values: Dict[str, Any]) -> Dict[str, Any]:
if "groups" in values and isinstance(values["groups"], List):
groups: List[Dict[str, Any]] = values["groups"]
if len(groups) > 0:
values["name"] = groups[0]["name_mi18n"]
values["season_id"] = groups[0]["schedule_id"]
values["begin_time"] = groups[0]["begin_time"]
values["end_time"] = groups[0]["end_time"]

return values

0 comments on commit 3b08bf7

Please sign in to comment.