From d87d4aeff407c0e5a700215d9abec86ba37ec8a4 Mon Sep 17 00:00:00 2001 From: Tyler Porter Date: Mon, 1 Jun 2026 20:00:28 -0400 Subject: [PATCH 1/2] Flatten all matching gamePk highlights across dates --- statsapi/__init__.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/statsapi/__init__.py b/statsapi/__init__.py index dd3b50e..275c7de 100644 --- a/statsapi/__init__.py +++ b/statsapi/__init__.py @@ -1056,12 +1056,20 @@ def game_highlight_data(gamePk): "fields": "dates,date,games,gamePk,content,highlights,items,headline,type,value,title,description,duration,playbacks,name,url", }, ) - gameHighlights = ( - r["dates"][0]["games"][0] - .get("content", {}) - .get("highlights", {}) - .get("highlights", {}) - ) + + gameHighlights = { "items": [] } + + for date in r["dates"]: + for game in date["games"]: + highlights = ( + game.get("content", {}) + .get("highlights", {}) + .get("highlights", {}) + .get("items", []) + ) + + gameHighlights["items"].extend(highlights) + if not gameHighlights or not len(gameHighlights.get("items", [])): return [] From 9c901fef8b3794071eaf5b5619ed0e204c46bd1d Mon Sep 17 00:00:00 2001 From: Tyler Porter Date: Tue, 2 Jun 2026 10:57:13 -0400 Subject: [PATCH 2/2] Simplify implementation --- statsapi/__init__.py | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/statsapi/__init__.py b/statsapi/__init__.py index 275c7de..9e074e9 100644 --- a/statsapi/__init__.py +++ b/statsapi/__init__.py @@ -1057,7 +1057,7 @@ def game_highlight_data(gamePk): }, ) - gameHighlights = { "items": [] } + gameHighlights = [] for date in r["dates"]: for game in date["games"]: @@ -1068,24 +1068,9 @@ def game_highlight_data(gamePk): .get("items", []) ) - gameHighlights["items"].extend(highlights) + gameHighlights.extend(h for h in highlights if isinstance(h, dict) and h.get("type") == "video") - if not gameHighlights or not len(gameHighlights.get("items", [])): - return [] - - unorderedHighlights = {} - for v in ( - x - for x in gameHighlights["items"] - if isinstance(x, dict) and x["type"] == "video" - ): - unorderedHighlights.update({v["date"]: v}) - - sortedHighlights = [] - for x in sorted(unorderedHighlights): - sortedHighlights.append(unorderedHighlights[x]) - - return sortedHighlights + return sorted(gameHighlights, key=lambda x: x["date"]) def game_pace(season=datetime.now().year, sportId=1):