Skip to content

Commit 58b24ae

Browse files
authored
Merge pull request #161 from WardBrian/add-season-to-player-stats
Allow 'season' argument to player_stats
2 parents 8da37f9 + bf5a161 commit 58b24ae

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

statsapi/__init__.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,9 +1122,9 @@ def game_pace_data(season=datetime.now().year, sportId=1):
11221122
return r
11231123

11241124

1125-
def player_stats(personId, group="[hitting,pitching,fielding]", type="season"):
1125+
def player_stats(personId, group="[hitting,pitching,fielding]", type="season", season=None):
11261126
"""Get current season or career stats for a given player."""
1127-
player = player_stat_data(personId, group, type)
1127+
player = player_stat_data(personId, group, type, season)
11281128

11291129
stats = ""
11301130
stats += player["first_name"]
@@ -1160,15 +1160,22 @@ def player_stats(personId, group="[hitting,pitching,fielding]", type="season"):
11601160

11611161

11621162
def player_stat_data(
1163-
personId, group="[hitting,pitching,fielding]", type="season", sportId=1
1163+
personId, group="[hitting,pitching,fielding]", type="season", sportId=1, season=None
11641164
):
11651165
"""Returns a list of current season or career stat data for a given player."""
1166+
1167+
if season is not None and 'season' not in type:
1168+
raise ValueError(
1169+
"The 'season' parameter is only valid when using the 'season' type."
1170+
)
1171+
11661172
params = {
11671173
"personId": personId,
11681174
"hydrate": "stats(group="
11691175
+ group
11701176
+ ",type="
11711177
+ type
1178+
+ (",season=" + str(season) if season else "")
11721179
+ ",sportId="
11731180
+ str(sportId)
11741181
+ "),currentTeam",

0 commit comments

Comments
 (0)