Skip to content

Commit 1614bf6

Browse files
authored
Merge pull request #102 from DatGuy1/patch-1
Check if highlights exist gracefully
2 parents ecf58c8 + e3bfa48 commit 1614bf6

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

statsapi/__init__.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,15 +1038,12 @@ 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-
if not len(
1042-
r["dates"][0]["games"][0]["content"]["highlights"]["highlights"]["items"]
1043-
):
1044-
return ""
1045-
1046-
items = r["dates"][0]["games"][0]["content"]["highlights"]["highlights"]["items"]
1041+
gameHighlights = r["dates"][0]["games"][0]["content"]["highlights"]["highlights"]
1042+
if not gameHighlights or len(gameHighlights["items"]) == 0:
1043+
return []
10471044

10481045
unorderedHighlights = {}
1049-
for v in (x for x in items if isinstance(x, dict) and x["type"] == "video"):
1046+
for v in (x for x in gameHighlights["items"] if isinstance(x, dict) and x["type"] == "video"):
10501047
unorderedHighlights.update({v["date"]: v})
10511048

10521049
sortedHighlights = []

0 commit comments

Comments
 (0)