Skip to content

Commit 44492cc

Browse files
committed
fix: handle missing highlights
chore: code formatting
1 parent ff0273e commit 44492cc

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

statsapi/__init__.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,12 +1038,19 @@ def game_highlight_data(gamePk):
10381038
"fields": "dates,date,games,gamePk,content,highlights,items,headline,type,value,title,description,duration,playbacks,name,url",
10391039
},
10401040
)
1041-
gameHighlights = r["dates"][0]["games"][0]["content"]["highlights"]["highlights"]
1042-
if not gameHighlights or len(gameHighlights["items"]) == 0:
1041+
gameHighlights = (
1042+
r["dates"][0]["games"][0]["content"]
1043+
.get("highlights", {})
1044+
.get("highlights", {})
1045+
.get("items", [])
1046+
)
1047+
if not len(gameHighlights):
10431048
return []
10441049

10451050
unorderedHighlights = {}
1046-
for v in (x for x in gameHighlights["items"] if isinstance(x, dict) and x["type"] == "video"):
1051+
for v in (
1052+
x for x in gameHighlights if isinstance(x, dict) and x["type"] == "video"
1053+
):
10471054
unorderedHighlights.update({v["date"]: v})
10481055

10491056
sortedHighlights = []

0 commit comments

Comments
 (0)