From 88c64bef68b7c02d6a3526c815db7cbaa0594d1c Mon Sep 17 00:00:00 2001 From: todd Date: Mon, 6 Mar 2023 09:26:18 -0500 Subject: [PATCH] fix: handle missing highlights --- statsapi/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/statsapi/__init__.py b/statsapi/__init__.py index cede9dc..f459968 100644 --- a/statsapi/__init__.py +++ b/statsapi/__init__.py @@ -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})