Skip to content

Commit

Permalink
fix: handle missing highlights
Browse files Browse the repository at this point in the history
  • Loading branch information
toddrob99 committed Mar 6, 2023
1 parent de0ea50 commit 88c64be
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions statsapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,17 +1039,19 @@ def game_highlight_data(gamePk):
},
)
gameHighlights = (
r["dates"][0]["games"][0]["content"]
r["dates"][0]["games"][0]
.get("content", {})
.get("highlights", {})
.get("highlights", {})
.get("items", [])
)
if not len(gameHighlights):
if not gameHighlights or not len(gameHighlights.get("items", [])):
return []

unorderedHighlights = {}
for v in (
x for x in gameHighlights if isinstance(x, dict) and x["type"] == "video"
x
for x in gameHighlights["items"]
if isinstance(x, dict) and x["type"] == "video"
):
unorderedHighlights.update({v["date"]: v})

Expand Down

0 comments on commit 88c64be

Please sign in to comment.