Skip to content

Commit bf5a161

Browse files
committed
Allow 'season' argument to player_stats
1 parent 270cc9a commit bf5a161

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
@@ -1120,9 +1120,9 @@ def game_pace_data(season=datetime.now().year, sportId=1):
11201120
return r
11211121

11221122

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

11271127
stats = ""
11281128
stats += player["first_name"]
@@ -1158,15 +1158,22 @@ def player_stats(personId, group="[hitting,pitching,fielding]", type="season"):
11581158

11591159

11601160
def player_stat_data(
1161-
personId, group="[hitting,pitching,fielding]", type="season", sportId=1
1161+
personId, group="[hitting,pitching,fielding]", type="season", sportId=1, season=None
11621162
):
11631163
"""Returns a list of current season or career stat data for a given player."""
1164+
1165+
if season is not None and 'season' not in type:
1166+
raise ValueError(
1167+
"The 'season' parameter is only valid when using the 'season' type."
1168+
)
1169+
11641170
params = {
11651171
"personId": personId,
11661172
"hydrate": "stats(group="
11671173
+ group
11681174
+ ",type="
11691175
+ type
1176+
+ (",season=" + str(season) if season else "")
11701177
+ ",sportId="
11711178
+ str(sportId)
11721179
+ "),currentTeam",

0 commit comments

Comments
 (0)