Skip to content

Commit

Permalink
Add key name check before accessing dict in challenge.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KT-Yeh committed Jun 29, 2024
1 parent b98bc54 commit 5cd28f9
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions genshin/models/starrail/chronicle/challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class StarRailChallenge(APIModel):
def __extract_name(cls, values: Dict[str, Any]) -> Dict[str, Any]:
if "seasons" in values and isinstance(values["seasons"], List):
seasons: List[Dict[str, Any]] = values["seasons"]
if len(seasons) > 0:
if len(seasons) > 0 and "name_mi18n" in seasons[0]:
values["name"] = seasons[0]["name_mi18n"]

return values
Expand Down Expand Up @@ -144,10 +144,14 @@ def __unnest_groups(cls, values: Dict[str, Any]) -> Dict[str, Any]:
if "seasons" in values and isinstance(values["seasons"], List):
seasons: List[Dict[str, Any]] = values["seasons"]
if len(seasons) > 0:
values["name"] = seasons[0]["name_mi18n"]
values["season_id"] = seasons[0]["schedule_id"]
values["begin_time"] = seasons[0]["begin_time"]
values["end_time"] = seasons[0]["end_time"]
if "name_mi18n" in seasons[0]:
values["name"] = seasons[0]["name_mi18n"]
if "schedule_id" in seasons[0]:
values["season_id"] = seasons[0]["schedule_id"]
if "begin_time" in seasons[0]:
values["begin_time"] = seasons[0]["begin_time"]
if "end_time" in seasons[0]:
values["end_time"] = seasons[0]["end_time"]

return values

Expand Down

0 comments on commit 5cd28f9

Please sign in to comment.