Skip to content

Commit 5c6a5b4

Browse files
committed
fix: next_game() should actually return next game
1 parent 426433a commit 5c6a5b4

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

statsapi/__init__.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -887,17 +887,24 @@ def last_game(teamId):
887887

888888

889889
def next_game(teamId):
890-
"""Get the gamePk for the given team's next game.
891-
Note: Sometimes Stats API will actually return the next game in the previousSchedule hydration
890+
"""Get the gamePk for the given team's next unstarted game.
892891
"""
893-
return get(
892+
nextSchedule = get(
894893
"team",
895894
{
896895
"teamId": teamId,
897896
"hydrate": "nextSchedule",
898-
"fields": "teams,id,teamName,nextGameSchedule,dates,date,games,gamePk,season,gameDate,teams,away,home,team,name",
897+
"fields": "teams,team,id,nextGameSchedule,dates,date,games,gamePk,gameDate,status,abstractGameCode",
899898
},
900-
)["teams"][0]["nextGameSchedule"]["dates"][0]["games"][0]["gamePk"]
899+
)
900+
games = []
901+
for d in nextSchedule["teams"][0]["nextGameSchedule"]["dates"]:
902+
games.extend([x for x in d["games"] if x["status"]["abstractGameCode"] == "P"])
903+
904+
if not len(games):
905+
return None
906+
907+
return games[0]["gamePk"]
901908

902909

903910
def game_scoring_plays(gamePk):

0 commit comments

Comments
 (0)