Skip to content

Commit 88c64be

Browse files
committed
fix: handle missing highlights
1 parent de0ea50 commit 88c64be

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

statsapi/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,17 +1039,19 @@ def game_highlight_data(gamePk):
10391039
},
10401040
)
10411041
gameHighlights = (
1042-
r["dates"][0]["games"][0]["content"]
1042+
r["dates"][0]["games"][0]
1043+
.get("content", {})
10431044
.get("highlights", {})
10441045
.get("highlights", {})
1045-
.get("items", [])
10461046
)
1047-
if not len(gameHighlights):
1047+
if not gameHighlights or not len(gameHighlights.get("items", [])):
10481048
return []
10491049

10501050
unorderedHighlights = {}
10511051
for v in (
1052-
x for x in gameHighlights if isinstance(x, dict) and x["type"] == "video"
1052+
x
1053+
for x in gameHighlights["items"]
1054+
if isinstance(x, dict) and x["type"] == "video"
10531055
):
10541056
unorderedHighlights.update({v["date"]: v})
10551057

0 commit comments

Comments
 (0)