用于python的mlb stats api包装器
MLB-StatsA的Python项目详细描述
MLB STATSAPI
用于mlb stats api的python包装器
由Todd Roberts创建
https://pypi.org/project/mlb statsapi/
https://github.com/toddrob99/mlb statsapi
文档:https://toddrob99.github.io/mlb-statsapi/" rel="nofollow">https://toddrob99.github.io/mlb statsapi/
安装
mlb statsapi列在python包索引中, 对于所有平台,首选的安装方法是pip。 如果您手动安装,请确保也安装请求。
pip安装mlb statsapi
可用功能
statsapi.get()
-直接调用mlb statsapi端点;支持请求参数的最大灵活性,并返回原始json数据statsapi.meta()
-从statsapi检索可用值以用于其他查询,或查找api结果中的值的说明statsapi.notes()
-检索给定端点的注释,包括所需参数的列表,以及某些端点的提示statsapi.lookup_player()
-根据名字、姓氏或全名、球衣号码、当前球队ID、位置等获取球员数据列表。statsapi.lookup_team()
-根据团队名称、城市、缩写或文件代码获取团队信息列表statsapi.schedule()
-检索给定日期/范围和/或团队/对手的游戏列表statsapi.boxScore()
-为给定游戏生成格式化的boxScorestatsapi.boxscore_data()
-生成包含给定游戏的boxscore数据的dictstatsapi.linescore()
-为给定游戏生成格式化的linescorestatsapi.floster()
-生成球队花名册上球员的格式化列表statsapi.standings()
-生成给定联盟/日期的标准列表statsapi.standings_data()
-返回给定联盟/日期的排名数据的python列表statsapi.team_leaders()
-生成给定状态的团队领导的格式化列表statsapi.team_leader_data()
-返回给定状态下团队负责人数据的python列表statsapi.league椆leaders()
-生成当前或指定赛季的统计领先者的格式化列表statsapi.league_leader_data()
-返回当前或指定季节的统计领导数据的python列表statsapi.player_stats()
-生成球员职业或赛季统计的格式化列表statsapi.player_stat_data()
-返回球员职业生涯或赛季统计数据的python dict,以及一些个人信息statsapi.last_game()
-获取给定团队最新游戏的游戏IDstatsapi.next_game()
-获取给定团队下一个游戏的游戏IDstatsapi.game_highlights()
-生成一个带有给定游戏视频链接的突出显示格式化列表statsapi.game_highlight_data()
-返回给定游戏的高光数据(包括视频链接)的python列表statsapi.game_pace()
-生成给定季节(早在1999年)的游戏速度信息的格式化列表statsapi.game_pace_data()
-返回给定季节(早在1999年)的游戏速度信息的python指令。statsapi.game_scoring_plays()
-生成给定游戏的评分播放格式化列表statsapi.game_scoring_play_data()
-返回给定游戏的python记录的得分播放数据。
示例使用
打印奥克兰田径队2018年赢得的比赛数
使用statsapi.schedule()
检索2018年A的所有游戏,
并使用sum()
计算结果集中A队获胜的记录。
print('The A\'s won %s games in 2018.' % sum(1 for x in statsapi.schedule(team=133,start_date='01/01/2018',end_date='12/31/2018') if x.get('winning_team','')=='Oakland Athletics'))
打印费城人队在2008年7月赢得的所有比赛的分数线
使用statsapi.schedule()
检索2018年7月的所有游戏,
通过列表理解来运行结果dict
反复查看费城人队获胜的记录,
并将游戏id
输入statsapi_linescore()
for x in [y for y in statsapi.schedule(team=143,start_date='07/01/2008',end_date='07/31/2008') if y.get('winning_team','')=='Philadelphia Phillies']:
print('%s\nWinner: %s, Loser: %s\n%s\n\n' % (x['game_date'], x['winning_team'], x['losing_team'], statsapi.linescore(x['game_id'])))
在2018赛季首日打印费城40人名单
使用statsapi.get('season')
检索2018年季节的日期,
将开幕日期输入statsapi.floster()
print('Phillies 40-man roster on opening day of the 2018 season:\n%s' % statsapi.roster(143,'40Man',date=statsapi.get('season',{'seasonId':2018,'sportId':1})['seasons'][0]['regularSeasonStartDate']))
打印A最近一场比赛(根据MLB对"最后一场比赛"请求的响应,可能正在进行或尚未开始)的箱分数和线分数。
使用statsapi.last_game()
检索最近的A游戏
并将gamepk输入statsapi.boxscore()
和statsapi.linescore()
most_recent_game_id = statsapi.last_game(133)
print(statsapi.boxscore(most_recent_game_id))
print(statsapi.linescore(most_recent_game_id))
找到名字最长的队伍
使用statsapi.get('teams')
检索所有活动的团队名称,
然后输入max()以查找最长的值及其长度
longest_team_name = max([x['name'] for x in statsapi.get('teams',{'sportIds':1,'activeStatus':'Yes','fields':'teams,name'})['teams']],key=len)
print('The team with the longest name is %s, at %s characters.' % (longest_team_name, len(longest_team_name)))
打印2018年7月4日起的积分榜
使用statsapi.standings()
和日期
参数
print(statsapi.standings(date='07/04/2018'))
打印出2008年费城人步行比赛的前5名领队
使用statsapi.team_leaders()
print(statsapi.team_leaders(143,'walks',limit=5,season=2008))
以双打形式打印前10名职业生涯领导者(注意:额外的8949条记录来自mlb的数据)
使用statsapi.league\u leaders()
print(statsapi.league_leaders('doubles',statGroup='hitting',statType='career',limit=10))
打印Chase Utley的职业命中统计信息
使用statsapi.get()
调用2008年世界大赛的Sports_Players终结点,
从结果中查找chase utley的个人ID,并将其传递到statsapi.player\u stats()
使用type='hitting'
和group='career'
print( statsapi.player_stats(next(x['id'] for x in statsapi.get('sports_players',{'season':2008,'gameType':'W'})['people'] if x['fullName']=='Chase Utley'), 'hitting', 'career') )
打印2019年4月28日《马林人@费城人》游戏的得分游戏列表
print('The A\'s won %s games in 2018.' % sum(1 for x in statsapi.schedule(team=133,start_date='01/01/2018',end_date='12/31/2018') if x.get('winning_team','')=='Oakland Athletics'))
0
版权声明
此软件包及其作者不隶属于mlb或任何mlb团队。这个api包装器与mlb的statsapi接口。MLB数据的使用以http://gdx.mlb.com/components/copyright.txt" rel="nofollow">http://gdx.mlb.com/components/copyright.txt上发布的通知为准。