Skip to content

Commit

Permalink
Merge pull request #39 from toddrob99/develop
Browse files Browse the repository at this point in the history
v0.1.7
  • Loading branch information
toddrob99 authored May 9, 2020
2 parents 670afdf + 3732a14 commit d180c4a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 19 additions & 1 deletion statsapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def boxscore_data(gamePk, timecode=None):
for batterId_int in [
x
for x in boxData[side]["batters"]
if boxData[side]["players"]["ID" + str(x)].get("battingOrder")
if boxData[side]["players"].get("ID" + str(x), {}).get("battingOrder")
]:
batterId = str(batterId_int)
namefield = (
Expand All @@ -506,6 +506,14 @@ def boxscore_data(gamePk, timecode=None):
+ " "
+ boxData[side]["players"]["ID" + batterId]["position"]["abbreviation"]
)
if not len(
boxData[side]["players"]["ID" + batterId]
.get("stats", {})
.get("batting", {})
):
# Protect against player with no batting data in the box score (#37)
continue

batter = {
"namefield": namefield,
"ab": str(
Expand Down Expand Up @@ -675,6 +683,15 @@ def boxscore_data(gamePk, timecode=None):
side = sides[i]
for pitcherId_int in boxData[side]["pitchers"]:
pitcherId = str(pitcherId_int)
if not boxData[side]["players"].get("ID" + pitcherId) or not len(
boxData[side]["players"]["ID" + pitcherId]
.get("stats", {})
.get("pitching", {})
):
# Skip pitcher with no pitching data in the box score (#37)
# Or skip pitcher listed under the wrong team (from comments on #37)
continue

namefield = boxData["playerInfo"]["ID" + pitcherId]["boxscoreName"]
namefield += (
" "
Expand Down Expand Up @@ -1091,6 +1108,7 @@ def player_stat_data(personId, group="[hitting,pitching,fielding]", type="season
stat_group = {
"type": s["type"]["displayName"],
"group": s["group"]["displayName"],
"season": s["splits"][i].get("season"),
"stats": s["splits"][i]["stat"],
}
stat_groups.append(stat_group)
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.6"
VERSION = "0.1.7"

0 comments on commit d180c4a

Please sign in to comment.