From 454ac3400aaa5cbde2fd381cae9c348356a72762 Mon Sep 17 00:00:00 2001 From: KT Date: Wed, 7 Feb 2024 19:21:37 +0800 Subject: [PATCH] Fix HSR pure fiction time data --- .../client/components/chronicle/starrail.py | 13 ++++++++++ .../models/starrail/chronicle/challenge.py | 26 +++---------------- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/genshin/client/components/chronicle/starrail.py b/genshin/client/components/chronicle/starrail.py index b1935341..4abc7757 100644 --- a/genshin/client/components/chronicle/starrail.py +++ b/genshin/client/components/chronicle/starrail.py @@ -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) diff --git a/genshin/models/starrail/chronicle/challenge.py b/genshin/models/starrail/chronicle/challenge.py index d71f2ee2..70fef2b9 100644 --- a/genshin/models/starrail/chronicle/challenge.py +++ b/genshin/models/starrail/chronicle/challenge.py @@ -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 @@ -95,10 +87,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 @@ -107,15 +99,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