Skip to content

Commit

Permalink
Merge pull request #45 from toddrob99/develop
Browse files Browse the repository at this point in the history
FIX: game_scoring_plays() and game_scoring_play_data() broken due to MLB data change #44
VER: 0.1.9
  • Loading branch information
toddrob99 authored Jul 26, 2020
2 parents 7b25339 + 21167c7 commit f4f7ebd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
38 changes: 25 additions & 13 deletions statsapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,30 +927,42 @@ def game_scoring_play_data(gamePk):
* plays - sorted list of scoring play data
"""
r = get(
"schedule",
"game",
{
"sportId": 1,
"gamePk": gamePk,
"hydrate": "scoringplays",
"fields": "dates,date,games,teams,away,team,name,scoringPlays,result,description,awayScore,homeScore,about,halfInning,inning,endTime",
"fields": (
"gamePk,link,gameData,game,pk,teams,away,id,name,teamCode,fileCode,"
"abbreviation,teamName,locationName,shortName,home,liveData,plays,"
"allPlays,scoringPlays,scoringPlays,atBatIndex,result,description,"
"awayScore,homeScore,about,halfInning,inning,endTime"
),
},
)
if not len(r["dates"][0]["games"][0]["scoringPlays"]):
return ""

items = r["dates"][0]["games"][0]["scoringPlays"]
home_team = r["dates"][0]["games"][0]["teams"]["home"]["team"]
away_team = r["dates"][0]["games"][0]["teams"]["away"]["team"]
if not len(r["liveData"]["plays"].get("scoringPlays", [])):
return {
"home": r["gameData"]["teams"]["home"],
"away": r["gameData"]["teams"]["away"],
"plays": [],
}

unorderedPlays = {}
for v in items:
unorderedPlays.update({v["about"]["endTime"]: v})
for i in r["liveData"]["plays"].get("scoringPlays", []):
play = next(
(p for p in r["liveData"]["plays"]["allPlays"] if p.get("atBatIndex") == i),
None,
)
if play:
unorderedPlays.update({play["about"]["endTime"]: play})

sortedPlays = []
for x in sorted(unorderedPlays):
sortedPlays.append(unorderedPlays[x])

return {"home": home_team, "away": away_team, "plays": sortedPlays}
return {
"home": r["gameData"]["teams"]["home"],
"away": r["gameData"]["teams"]["away"],
"plays": sortedPlays,
}


def game_highlights(gamePk):
Expand Down
2 changes: 1 addition & 1 deletion statsapi/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env python

VERSION = "0.1.8"
VERSION = "0.1.9"

0 comments on commit f4f7ebd

Please sign in to comment.