toddrob99 / MLB-StatsAPI

Python wrapper for MLB Stats API
GNU General Public License v3.0
533 stars 100 forks source link

Missing endpoint: team_stats #53

Closed toddrob99 closed 3 years ago

toddrob99 commented 3 years ago

Example URL: http://statsapi.mlb.com/api/v1/teams/137/stats?group=pitching&season=2018&stats=season

Example URL with sitCodes: http://statsapi.mlb.com/api/v1/teams/137/stats?group=pitching&season=2018&stats=statSplits&sitCodes=rp

toddrob99 commented 3 years ago

Adding endpoint definition to v1.2.

Example use:

# Get Phillies 2020 Pitching Stats
allpitching = statsapi.get("team_stats", {"teamId": 143, "season": 2020, "group": "pitching", "stats": "season"})
print(f"{allpitching=}")
relievers = statsapi.get("team_stats", {"teamId": 143, "season": 2020, "group": "pitching", "stats": "statSplits", "sitCodes": "rp"})
print(f"{relievers=}")

Output w/ debug logging:

2021-05-09 11:02:03,826 -    DEBUG - statsapi(54088) - URL: https://statsapi.mlb.com/api/{ver}/teams/{teamId}/stats
2021-05-09 11:02:03,827 -    DEBUG - statsapi(54088) - Found path param: teamId
2021-05-09 11:02:03,828 -    DEBUG - statsapi(54088) - Found query param: season
2021-05-09 11:02:03,828 -    DEBUG - statsapi(54088) - Found query param: group
2021-05-09 11:02:03,829 -    DEBUG - statsapi(54088) - Found query param: stats
2021-05-09 11:02:03,830 -    DEBUG - statsapi(54088) - path_params: {'teamId': '143'}
2021-05-09 11:02:03,830 -    DEBUG - statsapi(54088) - query_params: {'season': '2020', 'group': 'pitching', 'stats': 'season'}
2021-05-09 11:02:03,831 -    DEBUG - statsapi(54088) - Replacing {teamId}
2021-05-09 11:02:03,831 -    DEBUG - statsapi(54088) - URL: https://statsapi.mlb.com/api/{ver}/teams/143/stats
2021-05-09 11:02:03,832 -    DEBUG - statsapi(54088) - Replacing {ver} with default: v1.
2021-05-09 11:02:03,832 -    DEBUG - statsapi(54088) - URL: https://statsapi.mlb.com/api/v1/teams/143/stats
2021-05-09 11:02:03,833 -    DEBUG - statsapi(54088) - Adding query parameter season=2020
2021-05-09 11:02:03,833 -    DEBUG - statsapi(54088) - URL: https://statsapi.mlb.com/api/v1/teams/143/stats?season=2020
2021-05-09 11:02:03,834 -    DEBUG - statsapi(54088) - Adding query parameter group=pitching
2021-05-09 11:02:03,835 -    DEBUG - statsapi(54088) - URL: https://statsapi.mlb.com/api/v1/teams/143/stats?season=2020&group=pitching
2021-05-09 11:02:03,835 -    DEBUG - statsapi(54088) - Adding query parameter stats=season
2021-05-09 11:02:03,836 -    DEBUG - statsapi(54088) - URL: https://statsapi.mlb.com/api/v1/teams/143/stats?season=2020&group=pitching&stats=season
2021-05-09 11:02:03,840 -    DEBUG - urllib3.connectionpool(54088) - Starting new HTTPS connection (1): statsapi.mlb.com:443
2021-05-09 11:02:04,030 -    DEBUG - urllib3.connectionpool(54088) - https://statsapi.mlb.com:443 "GET /api/v1/teams/143/stats?season=2020&group=pitching&stats=season HTTP/1.1" 200 None
2021-05-09 11:02:04,033 -    DEBUG - statsapi(54088) - URL: https://statsapi.mlb.com/api/{ver}/teams/{teamId}/stats
2021-05-09 11:02:04,034 -    DEBUG - statsapi(54088) - Found path param: teamId
2021-05-09 11:02:04,034 -    DEBUG - statsapi(54088) - Found query param: season
2021-05-09 11:02:04,035 -    DEBUG - statsapi(54088) - Found query param: group
2021-05-09 11:02:04,036 -    DEBUG - statsapi(54088) - Found query param: stats
2021-05-09 11:02:04,036 -    DEBUG - statsapi(54088) - Found query param: sitCodes
2021-05-09 11:02:04,037 -    DEBUG - statsapi(54088) - path_params: {'teamId': '143'}
2021-05-09 11:02:04,038 -    DEBUG - statsapi(54088) - query_params: {'season': '2020', 'group': 'pitching', 'stats': 'statSplits', 'sitCodes': 'rp'}
2021-05-09 11:02:04,038 -    DEBUG - statsapi(54088) - Replacing {teamId}
2021-05-09 11:02:04,039 -    DEBUG - statsapi(54088) - URL: https://statsapi.mlb.com/api/{ver}/teams/143/stats
2021-05-09 11:02:04,039 -    DEBUG - statsapi(54088) - Replacing {ver} with default: v1.
2021-05-09 11:02:04,040 -    DEBUG - statsapi(54088) - URL: https://statsapi.mlb.com/api/v1/teams/143/stats
2021-05-09 11:02:04,040 -    DEBUG - statsapi(54088) - Adding query parameter season=2020
2021-05-09 11:02:04,041 -    DEBUG - statsapi(54088) - URL: https://statsapi.mlb.com/api/v1/teams/143/stats?season=2020
2021-05-09 11:02:04,041 -    DEBUG - statsapi(54088) - Adding query parameter group=pitching
2021-05-09 11:02:04,042 -    DEBUG - statsapi(54088) - URL: https://statsapi.mlb.com/api/v1/teams/143/stats?season=2020&group=pitching
2021-05-09 11:02:04,043 -    DEBUG - statsapi(54088) - Adding query parameter stats=statSplits
2021-05-09 11:02:04,044 -    DEBUG - statsapi(54088) - URL: https://statsapi.mlb.com/api/v1/teams/143/stats?season=2020&group=pitching&stats=statSplits
2021-05-09 11:02:04,044 -    DEBUG - statsapi(54088) - Adding query parameter sitCodes=rp
2021-05-09 11:02:04,045 -    DEBUG - statsapi(54088) - URL: https://statsapi.mlb.com/api/v1/teams/143/stats?season=2020&group=pitching&stats=statSplits&sitCodes=rp
2021-05-09 11:02:04,050 -    DEBUG - urllib3.connectionpool(54088) - Starting new HTTPS connection (1): statsapi.mlb.com:443
2021-05-09 11:02:04,207 -    DEBUG - urllib3.connectionpool(54088) - https://statsapi.mlb.com:443 "GET /api/v1/teams/143/stats?season=2020&group=pitching&stats=statSplits&sitCodes=rp HTTP/1.1" 200 None
allpitching={'copyright': 'Copyright 2021 MLB Advanced Media, L.P.  Use of any content on this page acknowledges agreement to the terms posted here http://gdx.mlb.com/components/copyright.txt', 'stats': [{'type': {'displayName': 'season'}, 'group': {'displayName': 'pitching'}, 'exemptions': [], 'splits': [{'season': '2020', 'stat': {'gamesPlayed': 60, 'gamesStarted': 60, 'groundOuts': 507, 'airOuts': 395, 'runs': 311, 'doubles': 117, 'triples': 8, 'homeRuns': 80, 'strikeOuts': 532, 'baseOnBalls': 185, 'intentionalWalks': 12, 'hits': 550, 'hitByPitch': 28, 'avg': '.279', 'atBats': 1971, 'obp': '.348', 'slg': '.468', 'ops': '.816', 'caughtStealing': 7, 'stolenBases': 23, 'stolenBasePercentage': '.767', 'groundIntoDoublePlay': 46, 'numberOfPitches': 8570, 'era': '5.14', 'inningsPitched': '497.0', 'wins': 28, 'losses': 32, 'saves': 11, 'saveOpportunities': 24, 'holds': 27, 'blownSaves': 13, 'earnedRuns': 284, 'whip': '1.48', 'battersFaced': 2197, 'outs': 1491, 'gamesPitched': 60, 'completeGames': 3, 'shutouts': 5, 'strikes': 5498, 'strikePercentage': '.640', 'hitBatsmen': 28, 'balks': 3, 'wildPitches': 14, 'pickoffs': 5, 'totalBases': 923, 'groundOutsToAirouts': '1.28', 'winPercentage': '.467', 'pitchesPerInning': '17.24', 'gamesFinished': 57, 'strikeoutWalkRatio': '2.88', 'strikeoutsPer9Inn': '9.63', 'walksPer9Inn': '3.35', 'hitsPer9Inn': '9.96', 'runsScoredPer9': '5.63', 'homeRunsPer9': '1.45', 'sacBunts': 4, 'sacFlies': 9}, 'team': {'id': 143, 'name': 'Philadelphia Phillies', 'link': '/api/v1/teams/143'}}]}]}
relievers={'copyright': 'Copyright 2021 MLB Advanced Media, L.P.  Use of any content on this page acknowledges agreement to the terms posted here http://gdx.mlb.com/components/copyright.txt', 'stats': [{'type': {'displayName': 'statSplits'}, 'group': {'displayName': 'pitching'}, 'exemptions': [], 'splits': [{'stat': {'gamesPlayed': 189, 'gamesStarted': 0, 'groundOuts': 175, 'airOuts': 164, 'runs': 159, 'doubles': 48, 'triples': 7, 'homeRuns': 42, 'strikeOuts': 203, 'baseOnBalls': 87, 'intentionalWalks': 8, 'hits': 246, 'hitByPitch': 13, 'avg': '.315', 'atBats': 782, 'obp': '.391', 'slg': '.555', 'ops': '.946', 'caughtStealing': 3, 'stolenBases': 12, 'stolenBasePercentage': '.800', 'groundIntoDoublePlay': 14, 'numberOfPitches': 3498, 'era': '7.06', 'inningsPitched': '186.0', 'wins': 9, 'losses': 14, 'saves': 11, 'saveOpportunities': 24, 'holds': 27, 'blownSaves': 13, 'earnedRuns': 146, 'whip': '1.79', 'battersFaced': 888, 'outs': 558, 'gamesPitched': 189, 'completeGames': 0, 'shutouts': 0, 'strikes': 2192, 'strikePercentage': '.630', 'hitBatsmen': 13, 'balks': 2, 'wildPitches': 8, 'pickoffs': 0, 'totalBases': 434, 'groundOutsToAirouts': '1.07', 'rbi': 161, 'winPercentage': '.391', 'pitchesPerInning': '18.81', 'gamesFinished': 57, 'strikeoutWalkRatio': '2.33', 'strikeoutsPer9Inn': '9.82', 'walksPer9Inn': '4.21', 'hitsPer9Inn': '11.90', 'runsScoredPer9': '7.69', 'homeRunsPer9': '2.03', 'inheritedRunners': 115, 'inheritedRunnersScored': 37, 'sacBunts': 2, 'sacFlies': 4}, 'team': {'id': 143, 'name': 'Philadelphia Phillies', 'link': '/api/v1/teams/143'}, 'split': {'code': 'rp', 'description': 'Reliever'}}]}]}