用于don-best sports api的易于使用的python包装器

donbest的Python项目详细描述


header image

build badgepypi badgeMIT license

donbest.py是一个易于使用的python包装器,用于Don Best Sports Data API.

安装

donbest.py可通过python包索引(pypi)下载。您可以使用pip或easy_install立即安装它。

pip install donbest

用法

要开始,您需要从don best网站上的token generator获取don best api令牌。一旦你明白了,你就准备好了。为了能够生成令牌,您需要在don best拥有一个帐户。您可以通过联系Don Best获得帐户。

>>> importdonbest>>> db=donbest.Donbest(api_token)

完成此操作后,现在可以使用db对象调用don best api。下面是一些示例:

获得即将到来的nba比赛的赔率

>>> events=don.schedule_inplay()>>> nba_events=[eventforeventineventsifevent.league.name=="NBA"]>>> foreventinnba_events:>>> print(event.get_live_odds())[<Line event=<Event id=817071, season=None, date=2018-05-25 01:05:00, opentime=None, name=None, event_type=None, event_state=None, time_changed=None, neutral=None, game_number=None, group=None, participants=None, league=None, location=None, live=None>, away_rot=507, home_rot=508, time=2018-05-23 15:20:21, period_id=1, period=FG, type=previous, sportsbook=347, ps=<PointSpread away_spread=0.00, home_spread=0.00, away_price=-110, home_price=-110>, money=<MoneyLine away_money=-110, home_money=-110, draw_money=0>, total=<Total total=220.00, over_price=-110, under_price=-110>, team_total=<TeamTotal away_total=109.50, away_over_price=-115, away_under_price=-105, home_total=110.00, home_over_price=-105, home_under_price=-115>, display_away=-1, display_home=219%BD, no_line=None>,
....]

活动日程

播放时间表:

返回未来几天的预定比赛和建议的列表。不返回在当天之前已经进行过的比赛。

>>> schedule=db.schedule_inplay()>>> event=schedule[0]>>> event<Event id=806300, season=regular, date=None, opentime=2018-09-07 00:20:00+00:00, name=Atlanta Falcons vs Philadelphia Eagles, event_type=None, event_state=circled, time_changed=False, neutral=False, game_number=1, group=<Group id=515449, name=None, description=NFL WEEK 1 (REGULAR SEASON) - Thursday, September 6th, type=event, type_id=1>, participants=[<Team id=11, name=Atlanta Falcons, abbreviation=atlanta, full_name=None, information=None, league=None, rotation=451, side=away>, <Team id=2, name=Philadelphia Eagles, abbreviation=philadelphia, full_name=None, information=None, league=None, rotation=452, side=home>], league=<League id=1, name=NFL, abbreviation=None, information=None, sport=<Sport id=1, name=Football, abbreviation=None, information=None>>, location=<Location id=680, name=Lincoln Financial Field, description=None, abbreviation=None, stadium_type=None, surface_type=None, seating_capacity=None, elevation=None, city=None>, live=True, event_state_id=10>

# Available Event attributes:
event.id
event.season
event.date
event.opentime
event.name
event.event_type
event.event_state
event.time_changed
event.neutral
event.game_number
event.group
event.group.id
event.group.name
event.group.type
event.group.type_id
event.live

## See Team section to view what attributes are
## available on the items returned in the list of
## participants
event.participants

## See League section for what attributes
## are available on League objects
event.league

## See Location section for what attributes
## may be available on Location objects
event.location

# Available methods:
event.get_live_odds()
event.get_opening_odds()
event.get_closing_odds()
event.get_score()

完整日程:

以下任何一个命令都会返回即将到来的活动的全部日程,包括未来几个月的比赛和命题。

>>> db.schedule()>>> db.current_schedue()[<Event id=819810, .... >,
<Event id =819811, .... >,
........................]

得分

返回包含实时比赛状态、当前分数和时段摘要的列表。唐最好确保他们的期间分数是正确的,而不使用第三方供应商,这意味着分数是实时和准确的。

现场评分:

>>> scores=db.score()>>> score=scores[0]<Score id=818854, league_id=12, away_rot=8205, home_rot=8206, away_score=6, home_score=7, description=FINAL, time=2018-05-22 14:18:26+00:00, period=FINAL, period_id=0, away_score_ext=None, home_score_ext=None, period_summary=[<Period name=Set 1, description=END-, time=2018-05-22 12:36:26+00:00, period_id=331, scores=[{'rot': '8205', 'value': '6'}, {'rot': '8206', 'value': '2'}]>, <Period name=Set 2, description=END-, time=2018-05-22 13:27:28+00:00, period_id=332, scores=[{'rot': '8205', 'value': '6'}, {'rot': '8206', 'value': '7'}]>, <Period name=Set 3, description=END-, time=2018-05-22 14:18:26+00:00, period_id=333, scores=[{'rot': '8205', 'value': '6'}, {'rot': '8206', 'value': '7'}]>]>

# Available Score attributes:
## The Score id is the id of the event it relates to...they are the same value
score.id
score.league_id
score.away_rot
score.home_rot
score.away_score
score.home_score
score.description
score.time
score.period
score.period_id
score.away_score_ext
score.home_score_ext

for period in score.period_summary:
    period.name
    period.description
    period.time_changed
    period.id
    for score in period.scores:
        score["rot"]
        score["value"]

线路

按联盟返回比赛和命题的开赛赔率、现场赔率和收场赔率列表。league id是所有行端点的必需参数

开局赔率(NBA):

>>> nba_lines=db.open(league_id=3)>>> line=nba_lines[0]<Line event=<Event id=817069, season=None, date=2018-05-23 01:05:00+00:00, opentime=None, name=None, event_type=None, event_state=None, time_changed=None, neutral=None, game_number=None, group=None, participants=None, league=None, location=None, live=None>, away_rot=505, home_rot=506, time=2018-05-22 21:11:47+00:00, period_id=1, period=FG, type=previous, sportsbook=347, ps=<PointSpread away_spread=8.00, home_spread=-8.00, away_price=-110, home_price=-110>, money=<MoneyLine away_money=330, home_money=-430, draw_money=0>, total=<Total total=226.50, over_price=-110, under_price=-110>, team_total=<TeamTotal away_total=109.00, away_over_price=-110, away_under_price=-110, home_total=117.50, home_over_price=-110, home_under_price=-110>, display_away=226%BD, display_home=-8%BD>

# Available Line attributes:
line.event
line.away_rot
line.home_rot
line.time
line.period_id
line.period
line.type
line.sportsbook
line.no_line
line.display_home
line.display_away
line.ps
line.ps.away_spread
line.ps.home_spread
line.ps.away_price
line.ps.home_price
line.money
line.money.away_money
line.money.home_money
line.money.draw_money
line.total
line.total.total
line.total.over_price
line.total.under_price
line.team_total
line.team_total.away_total
line.team_total.away_over_price
line.team_total.away_under_price
line.team_total.home_total
line.team_total.home_over_price
line.team_total.home_under_price

现场赔率和收场赔率(NBA):

>>> db.odds(league_id=3)>>> db.close(league_id=3)

团队

返回由don best sports/v2/team覆盖的团队列表

>>> teams=db.team()>>> team=teams[0]<Team id=1, name=Washington, abbreviation=WAS, full_name=Washington Redskins, information=nfc - east, league=<League id=1, name=NFL, abbreviation=None, information=None, sport=<Sport id=1, name=Football, abbreviation=None, information=None>>, rotation=None, side=None>>

# Available Team attributes:
team.id
team.name
team.abbreviation
team.full_name
team.information
team.league
team.rotation
team.side

联赛

返回don best sports覆盖的联赛列表/v2/league

>>> leagues=db.league()>>> league=leagues[0]<League id=1, name=NFL, abbreviation=NFL, information=None, sport=<Sport id=1, name=Football, abbreviation=FB, information=None>

# Available League attributes
league.id
league.name
league.abbreviation
league.information
league.sport

体育书籍

返回由don best sports/v2/sportsbook覆盖的体育书籍列表

>>> sportsbooks=db.sportsbook()>>> sportsbook=sportsbooks[0]<Sportsbook id=276, name=5D Reduced Juice, abbreviation=5DReduced>

# Available Sportsbook attributes:
sportsbook.id
sportsbook.name
sportsbook.abbreviation

运动

返回由don best sports/v2/sport覆盖的运动列表

>>> sports=db.sport()>>> sport=sports[1]<Sport id=1, name=Football, abbreviation=FB, information=None>

# Available Sports attributes:
sport.id
sport.name
sport.abbreviation
sport.information

位置

返回时间表提要中所有比赛的体育场和竞技场列表。/v2/位置

>>> locations=db.location()>>> location=locations[0]<Location id=1, name=Wilson Stadium, description=None, abbreviation=None, stadium_type=None, surface_type=None, seating_capacity=75339, elevation=0, city=<City id=2, name=Buffalo, country=USA, postalCode=14127, state=NY>>

# Available Location attributes:
location.id
location.name
location.description
location.abbreviation
location.stadium_type
location.surface_type
location.seating_capacity
location.elevation
location.city
location.city.id
location.city.name
location.city.country
location.city.postalCode
location.city.state

其他

默认情况下,donbest.py将返回已解析的python对象。如果您想要请求的原始xml响应,只需传入parse_response=False

>>> response=db.schedule_inplay(parse_response=False)>>> responseb'<?xml version="1.0" encoding="utf-8"?>\n<don_best_sports><id>schedule_inplay</id><updated>2018-05-22T13:16:32+0</updated><schedule><sport id="1" name="Football">....

在大多数情况下,对象属性的值将按预期的类型返回(例如,日期将作为原生python datetime对象返回)。不同的主要场景是每个对象的唯一“id”。所有唯一的id都作为字符串返回。这里引用了don-best api文档中的一段话来说明这种方法。

Note: The Don Best Sports API exposes identifiers for uniquely identifiable objects such as Events, Teams and Sports Books. These IDs should always be treated as opaque strings, rather than integers of any specific type. The format of the IDs can change over time, so relying on the current format may cause you problems in the future

don best.py将1-1映射到don best sports api(例如,db.one.two.three()将 向“http://xml.donbest.com/v2/one/two/three”发送请求。但是,库当前不支持event_statemarket_list终结点。它也不支持don-best流式消息api,因为这要求您的ip被白名单,这使得测试更加困难。

有关所有方法和用法的详细信息,请阅读Don Best Sports API documentation.

许可证MIT license

麻省理工学院执照。详见LICENSE

待办事项

  • 添加对端点的支持
  • 添加对流式处理API的支持
  • 添加选项以使所有对象以正确格式的嵌套词典返回

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
安卓 java。lang.NullPointerException:uriString   如何使IntelliJ IDEA支持Java 7功能?   如何最好地将这个java方法翻译成python   eclipse java。lang.IllegalStateException:设置后无法更改位置   java连接超时在HttpClient中不起作用   java在Eclipse中添加JPA连接   java我需要帮助来构建一个返回数组的方法   c#从Internet Explorer 8中的ActiveX控件中提取数据   java使用varargs传递参数对,而不会遇到错误模式   java使用jQuery读取txt文件时无法返回函数外的值   ApachePOI如何在Java中获取“last saved by”Office文件属性   to date JavaTo_date()在可调用语句中   向maven添加依赖项时出现java问题   java Selenium服务器,在ASP中单击定位器。NET网页工作不稳定