diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..d0a15b3 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,15 @@ +language: python + +python: + - "2.7" + - "3.4" + +# command to install dependencies +install: pip install -r requirements.txt + +# command to run tests +script: python demo.py + +branches: + only: +- master \ No newline at end of file diff --git a/README.md b/README.md index ba765e5..3dd6261 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,16 @@ -# betsapi-python -python SDK of betsapi +## betsapi-python + +python SDK of betsapi.com. +betsapi.com is a excellent api for bet app. + +## docs + +https://betsapi.com/docs/ + +## gitbook + +https://github.com/fayland/betsapi-gitbook + +## translations + +https://github.com/fayland/betsapi-translation/ diff --git a/betsapi/__init__.py b/betsapi/__init__.py new file mode 100644 index 0000000..03ad3b6 --- /dev/null +++ b/betsapi/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +""" +BetsAPI library +""" +__version__ = '1.0.0' + +from .bet365 import Bet365 +from .betfair import Betfair +from .betway import Betway +from .bwin import BWin +from .events import Events +from .results import Results +from .sbobet import Sbobet + +__all__ = ("Bet365", "Betfair", "Betway","BWin","Events","Results","Sbobet") diff --git a/betsapi/baseapi.py b/betsapi/baseapi.py new file mode 100644 index 0000000..efe7a78 --- /dev/null +++ b/betsapi/baseapi.py @@ -0,0 +1,28 @@ +# -*- coding:utf-8 -*- + +import os +import sys +import json +import requests + + +class BaseBetsAPI(object): + + + def __init__(self): + + self.token = None + + + def build_uri(self, url, endpoint): + r""" + :param `url`:(required), url should not end with '/'. + :param `endpoint`:(required),endpoint should not start with '/'. + """ + return '/'.join([url, endpoint]) + + def set_lng(self, lng_id): + r"""set language. + :param `lng_id`:(required),see [faq](https://betsapi.com/docs/events/faq.html) for more details. + """ + self.LNG_ID = str(lng_id) diff --git a/betsapi/bet365.py b/betsapi/bet365.py new file mode 100644 index 0000000..826e32d --- /dev/null +++ b/betsapi/bet365.py @@ -0,0 +1,164 @@ +#!/usr/bin/env python +#-*-coding:utf-8-*- +import json +import os +import re +import sys + +import requests + +from .baseapi import BaseBetsAPI + + +class Bet365(BaseBetsAPI): + """ + Bet365 library. + """ + + def __init__(self, token): + r""" + :param `token`: required. + """ + + self.token = token + + # English by default + self.LNG_ID = '1' + + v1_bet365='https://api.betsapi.com/v1/bet365' + + self._inplay= self.build_uri(v1_bet365,'inplay') + self._inplay_filter = self.build_uri(v1_bet365,'inplay_filter') + self._inplay_event= self.build_uri(v1_bet365,'event') + self._upcoming_events= self.build_uri(v1_bet365,'upcoming') + self._prematch_odds= self.build_uri(v1_bet365,'start_sp') + self._result= self.build_uri(v1_bet365,'result') + + + def inplay(self,raw=None): + r"""Bet365 InPlay + + :param `raw`:(optional),raw Bet365 body without parsing. + """ + params = { + 'token': self.token + } + + if raw: + params['raw'] = raw + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._inplay, params=params) + return json.loads(req.content) + + def inplay_filter(self,sport_id,league_id=None): + r"""Bet365 InPlay Filter + + :param `sport_id`:(required),see [R-SportID](https://betsapi.com/docs/GLOSSARY.html#r-sportid) for more details. + :param `league_id`:(optional),useful when you want only one league. + Note: there is no pager in this API call. we just return all events. + """ + params = { + 'sport_id':sport_id, + 'token': self.token + } + + if league_id: + params['league_id'] = league_id + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._inplay_filter, params=params) + return json.loads(req.content) + + def inplay_event(self,FI,stats=None,lineup=None,raw=None): + r"""Bet365 Inplay Event + + :param `FI`:(required),FI from Bet365 Inplay. + :param `stats`: (optional),extra stats info (only provided for Soccer and Cricket). + :param `lineup`:(optional),lineup info (only provided for Cricket right now). + :param `raw`:(optional),raw Bet365 body without parsing. + """ + params = { + 'FI':FI, + 'token': self.token + } + + if stats: + params['stats']=stats + if lineup: + params['lineup']=lineup + if raw: + params['raw']=raw + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._inplay_event, params=params) + return json.loads(req.content) + + def upcoming_events(self,sport_id,league_id=None,day=None,page=None): + r"""Bet365 Upcoming Events + + :param `sport_id`:(required),see [R-SportID](https://betsapi.com/docs/GLOSSARY.html#r-sportid) for more details. + :param `league_id`:(optional),useful when you want only one league. + :param `day`:(optional),format YYYYMMDD, eg: 20161201. + :param `page`:(optional),see [R-Pager](https://betsapi.com/docs/GLOSSARY.html#r-pager) for more details. + """ + params = { + 'sport_id':sport_id, + 'token': self.token + } + if league_id: + params['league_id'] = league_id + if day: + params['day']= day + if page: + params['page'] = page + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + + req = requests.get(self._upcoming_events, params=params) + return json.loads(req.content)['results'] + + def prematch_odds(self,FI,raw=None): + r"""Bet365 PreMatch Odds + + :param `FI`:(required),Event ID you get from bet365/upcoming. + :param `raw`:(optional),raw Bet365 body without parsing. + """ + params = { + 'FI':FI, + 'token': self.token + } + + if raw: + params['raw'] = raw + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._prematch_odds, params=params) + return json.loads(req.content)['results'] + + def result(self,event_id): + r"""Bet365 Result + + :param `event_id`:(required),Event ID (FI) from Bet365 Inplay. + Note:you can send multiple event_ids in one request with event_id=1,2,3,4 up to max 10 ids. + """ + params = { + 'event_id':event_id, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._result, params=params) + return json.loads(req.content) diff --git a/betsapi/betfair.py b/betsapi/betfair.py new file mode 100644 index 0000000..9bcb7da --- /dev/null +++ b/betsapi/betfair.py @@ -0,0 +1,185 @@ +#!/usr/bin/env python +#-*-coding:utf-8-*- +import requests +import json +from .baseapi import BaseBetsAPI + + +class Betfair(BaseBetsAPI): + r"""Betfair library. + + Sportsbook and Exchange: + `Sportsbook` API is related to Sportsbook tab as https://www.betfair.com/sport/. + `Exchange` API is related to Exchange tab as https://www.betfair.com/exchange/plus/. + """ + + def __init__(self, token): + + self.token = token + # English by default + self.LNG_ID = '1' + + self._sb_inplay = 'https://api.betsapi.com/v1/betfair/sb/inplay' + self._sb_upcoming = 'https://api.betsapi.com/v1/betfair/sb/upcoming' + self._sb_event = 'https://api.betsapi.com/v1/betfair/sb/event' + self._ex_inplay = 'https://api.betsapi.com/v1/betfair/ex/inplay' + self._ex_upcoming = 'https://api.betsapi.com/v1/betfair/ex/upcoming' + self._ex_event = 'https://api.betsapi.com/v1/betfair/ex/event' + self._timeline = 'https://api.betsapi.com/v1/betfair/timeline' + self._result = 'https://api.betsapi.com/v1/betfair/result' + + def sb_inplay(self, sport_id=None,page=None): + r"""Sportsbook InPlay + + :param `sport_id`:(optional),Betfair eventTypeId. + :param `page`:(optional),see [R-Pager](https://betsapi.com/docs/GLOSSARY.html#r-pager)for more details. + """ + params = { + 'token': self.token + } + + if sport_id: + params['sport_id'] = sport_id + if page: + params['page'] = page + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._sb_inplay, params=params) + return json.loads(req.content) + + def sb_upcoming(self, sport_id=None,day=None,page=None): + r"""Sportsbook Upcoming + + :param `sport_id`:(optional),Betfair eventTypeId. + :param `day`:(optional),format YYYYMMDD, eg: 20161201. + :param `page`:(optional),see [R-Pager](https://betsapi.com/docs/GLOSSARY.html#r-pager) for more details. + """ + params = { + 'token': self.token + } + + if sport_id: + params['sport_id'] = sport_id + if day: + params['day'] = day + if page: + params['page'] = page + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._sb_inplay, params=params) + return json.loads(req.content) + + def sb_event(self, event_id): + r"""Sportsbook Event + + :param `event_id`:(required),Event ID you get from /betfair/inplay or upcoming. + """ + params = { + 'event_id':event_id, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._sb_inplay, params=params) + return json.loads(req.content) + + def ex_inplay(self, sport_id=None,page=None): + r"""Exchange InPlay + + :param `sport_id`:(optional),Betfair eventTypeId. + :param `page`:(optional),see [R-Pager](https://betsapi.com/docs/GLOSSARY.html#r-pager)for more details. + """ + params = { + 'token': self.token + } + + if sport_id: + params['sport_id'] = sport_id + if page: + params['page'] = page + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._sb_inplay, params=params) + return json.loads(req.content) + + def ex_upcoming(self, sport_id=None,day=None,page=None): + r"""Exchange Upcoming + + :param `sport_id`:(optional),Betfair eventTypeId. + :param `day`:(optional),format YYYYMMDD, eg: 20161201. + :param `page`:(optional),see [R-Pager](https://betsapi.com/docs/GLOSSARY.html#r-pager) for more details. + """ + params = { + 'token': self.token + } + + if sport_id: + params['sport_id'] = sport_id + if day: + params['day'] = day + if page: + params['page'] = page + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._sb_inplay, params=params) + return json.loads(req.content) + + def ex_event(self, event_id): + r"""Exchange Event + + :param `event_id`:(required),Event ID you get from /betfair/inplay or upcoming. + """ + params = { + 'event_id':event_id, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._sb_inplay, params=params) + return json.loads(req.content) + + def timeline(self,event_id): + r"""Betfair Timeline + + :param `event_id`:(required),Event ID you get from /betfair/inplay. + """ + params = { + 'event_id':event_id, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._timeline, params=params) + return json.loads(req.content) + + def result(self,event_id): + r"""Betfair Result + Note a few of (less than 3%) events are not covered. + + :param `event_id`:(required),Event ID you get from /betfair/inplay. + """ + params = { + 'event_id':event_id, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._result, params=params) + return json.loads(req.content) + \ No newline at end of file diff --git a/betsapi/betway.py b/betsapi/betway.py new file mode 100644 index 0000000..2e77e9f --- /dev/null +++ b/betsapi/betway.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python +#-*-coding:utf-8-*- +import requests +import json +from .baseapi import BaseBetsAPI + +v1_bet365='https://api.betsapi.com/v1/bet365' + + +class Betway(BaseBetsAPI): + r"""Betway library. + """ + + def __init__(self, token): + self.token = token + # English by default + self.LNG_ID = '1' + + self._inplay = 'https://api.betsapi.com/v1/betway/inplay' + self._upcoming = 'https://api.betsapi.com/v1/betway/upcoming' + self._event = 'https://api.betsapi.com/v1/betway/event' + self._result = 'https://api.betsapi.com/v1/betway/result' + + def inplay(self, event_id=None,page=None): + r"""Betway InPlay + + :param `event_id`:(optional),[R-SportID](https://betsapi.com/docs/GLOSSARY.html#r-sportid) (only 1-Soccer, 18-Basketball, 3-Cricket are supported now). + :param `page`:(optional),[R-Pager](https://betsapi.com/docs/GLOSSARY.html#r-pager). + """ + params = { + 'token': self.token + } + + if event_id: + params['event_id'] = event_id + if page: + params['page'] = page + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._inplay, params=params) + return json.loads(req.content) + + + def upcoming(self, sport_id = None,day = None, page = None): + r"""Betway Upcoming + + :param `sport_id`:(optional),[R-SportID](https://betsapi.com/docs/GLOSSARY.html#r-sportid) (only 1-Soccer, 18-Basketball, 3-Cricket are supported now). + :param `day`:(optional),format YYYYMMDD, eg: 20161201. + :param `page`:(optional),[R-Pager](https://betsapi.com/docs/GLOSSARY.html#r-pager). + + """ + params = { + 'token': self.token + } + + if sport_id: + params['sport_id'] = sport_id + if day: + params['day'] = day + if page: + params['page'] = page + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._upcoming, params=params) + return json.loads(req.content) + + + def event(self, event_id): + r"""Betway Event + + :param `event_id`:(required),Event ID you get from /betway/inplay or upcoming. + you can send multiple event_ids in one request with event_id=1,2,3,4 up to max 10 ids. + """ + params = { + 'event_id': event_id, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._event ,params=params) + return json.loads(req.content) + + + def result(self, event_id): + r"""Betway Result + Note a few of (less than 3%) events are not covered. + + :param `event_id`:(required),Event Id from Betway API. + you can send multiple event_ids in one request with event_id=1,2,3,4 up to max 10 ids. + """ + params = { + 'event_id': event_id, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._result, params=params) + return json.loads(req.content) + + + \ No newline at end of file diff --git a/betsapi/bwin.py b/betsapi/bwin.py new file mode 100644 index 0000000..349d67f --- /dev/null +++ b/betsapi/bwin.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python +#-*-coding:utf-8-*- +import requests +import json +from .baseapi import BaseBetsAPI + + +v1_bet365='https://api.betsapi.com/v1/bet365' + +class BWin(BaseBetsAPI): + r"""BWin library. + """ + + def __init__(self, token): + self.token = token + + # English by default + self.LNG_ID = '1' + + self._inplay = 'https://api.betsapi.com/v1/bwin/inplay' + self._event = 'https://api.betsapi.com/v1/bwin/event' + self._prematch = 'https://api.betsapi.com/v1/bwin/prematch' + self._result = 'https://api.betsapi.com/v1/bwin/result' + + + def inplay(self): + r"""BWin InPlay + """ + params = { + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._inplay, params=params) + return json.loads(req.content) + + def event(self, event_id): + r"""BWin Event + + :param `event_id`:(required),Event ID you get from /bwin/inplay or prematch. + you can send multiple `event_ids` in one request with `event_id`=1,2,3,4 up to max 10 ids. + """ + params = { + 'event_id': event_id, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._event, params=params) + return json.loads(req.content) + + def prematch(self,day=None,sport_id=None,league_id=None): + r"""BWin Prematch Odds + + :param `day`:(optional),format YYYYMMDD, eg: 20161201. + :param `sport_id`:(optional),BWin sport_id. + :param `league_id`:(optional),BWin league_id. + """ + params = { + 'token': self.token + } + + if day: + params['day'] = day + if sport_id: + params['sport_id'] = sport_id + if league_id: + params['league_id'] = league_id + + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._prematch, params=params) + return json.loads(req.content) + + def result(self, event_id): + r"""BWin Result + Note a few of (less than 3%) events are not covered. + + :param `event_id`:required,eventid from BWin API. + """ + params = { + 'event_id': event_id, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._result, params=params) + return json.loads(req.content) + + \ No newline at end of file diff --git a/betsapi/events.py b/betsapi/events.py new file mode 100644 index 0000000..6bab5ef --- /dev/null +++ b/betsapi/events.py @@ -0,0 +1,372 @@ +#!/usr/bin/env python +#-*-coding:utf-8-*- +import requests +import json +from .baseapi import BaseBetsAPI + + +class Events(BaseBetsAPI): + r"""Events library. + """ + + v1_event = 'https://api.betsapi.com/v1/event' + v2_event = 'https://api.betsapi.com/v2/event' + + v1_events = 'https://api.betsapi.com/v1/events' + v2_events = 'https://api.betsapi.com/v2/events' + + v1_league = 'https://api.betsapi.com/v1/league' + v1_team = 'https://api.betsapi.com/v1/team' + + def __init__(self, token): + self.token = token + + # English by default + self.LNG_ID = '1' + + self._inplay_events = self.build_uri(v1_events, 'inplay') + self._upcoming_events = self.build_uri(v2_events, 'upcoming') + self._ended_events = self.build_uri(v2_events, 'ended') + self._events_search = self.build_uri(v1_events, 'search') + self._event_view = self.build_uri(v1_event, 'view') + self._event_history = self.build_uri(v1_event, 'history') + self._event_odds_summary = self.build_uri(v1_event, 'odds/summary') + self._event_odds = self.build_uri(v1_event, 'odds') + self._event_stats_trend = self.build_uri(v1_event, 'stats_trend') + self._event_lineup = self.build_uri(v1_event, 'lineup') + self._event_videos = self.build_uri(v1_events, 'videos') + self._league = self.build_uri(v1_league, '') + self._league_table = self.build_uri(v1_league, 'table') + self._league_toplist = self.build_uri(v1_event, 'toplist') + self._team = self.build_uri(v1_team, '') + self._team_squad = self.build_uri(v1_team, 'squad') + + def inplay_events(self, sport_id,league_id=None): + r"""InPlay Events + + :param `sport_id`: (required),see [r-sportid](https://betsapi.com/docs/GLOSSARY.html#r-sportid) for more details. + :param `league_id`: (optional),useful when you want only one league. + """ + + params = { + 'sport_id': sport_id, + 'token': self.token + } + + if league_id: + params['league_id'] = league_id + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._inplay_events, params=params) + return json.loads(req.content) + + def upcoming_events(self, sport_id, league_id=None, team_id=None, cc=None, day=None, page=None): + r"""Upcoming Events + + :param `sport_id`:(required),[R-SportID](https://betsapi.com/docs/GLOSSARY.html#r-sportid). + :param `league_id`:(optional),useful when you want only one league. + :param `team_id`:(optional),useful when you want only one team. + :param `cc`:(optional),Eg: 'co' for Colombia ([R-Countries](https://betsapi.com/docs/GLOSSARY.html#r-countries)). + :param `day`:(optional),format YYYYMMDD, eg: 20161201. + :param `page`:(optional),[R-Pager](https://betsapi.com/docs/GLOSSARY.html#r-pager). + """ + params = { + 'sport_id': sport_id, + 'token': self.token + } + if league_id: + params['league_id'] = league_id + if team_id: + params['team_id'] = team_id + if cc: + params['cc'] = cc + if day: + params['day'] = day + if page: + params['page'] = page + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._upcoming_events, params=params) + return json.loads(req.content) + + def ended_events(self, sport_id, league_id=None, team_id=None, cc=None, day=None, page=None): + r"""Ended Events + + :param `sport_id`:(required),[R-SportID](https://betsapi.com/docs/GLOSSARY.html#r-sportid). + :param `league_id`:(optional),useful when you want only one league. + :param `team_id`:(optional),useful when you want only one team. + :param `cc`:(optional),Eg: 'co' for Colombia ([R-Countries](https://betsapi.com/docs/GLOSSARY.html#r-countries)). + :param `day`:(optional),format YYYYMMDD, eg: 20161201. + :param `page`:(optional),[R-Pager](https://betsapi.com/docs/GLOSSARY.html#r-pager). + """ + params = { + 'sport_id': sport_id, + 'token': self.token + } + if league_id: + params['league_id'] = league_id + if team_id: + params['team_id'] = team_id + if cc: + params['cc'] = cc + if day: + params['day'] = day + if page: + params['page'] = page + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._ended_events, params=params) + return json.loads(req.content) + + def events_search(self, sport_id, home, away, time): + r"""Events Search + Search for event with home/away name plus date. + + :param `sport_id`:(required),see [Reference](https://cn.betsapi.com/docs/events/search.html#sport_id) for more details. + :param `home`:(required),home team ID or name. + :param `away`:(required),away team ID or name. + :param `time`:(required),either UTC time epoch (Limited to 90 days) or day YYYYMMDD. + """ + params = { + 'sport_id': sport_id, + 'home': home, + 'away': away, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._events_search, params=params) + return json.loads(req.content) + + def event_view(self, event_id): + r"""Event View + + :param `event_id`:(required),Event ID you get from events/* . + you can send multiple event_ids in one request with event_id=1,2,3,4 up to max 10 ids. + """ + params = { + 'event_id': event_id, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._event_view, params=params) + return json.loads(req.content) + + def event_history(self, event_id, qty=None): + r"""Event History + History events of Home/Away Team before this event. + + :param `event_id`:(required),Event ID you get from events/*. + :param `qty`:(optional),default 10, allowing 1 to 20. + """ + params = { + 'event_id': event_id, + 'token': self.token + } + if qty: + params['qty'] = qty + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._event_history, params=params) + return json.loads(req.content) + + def event_odds_summary(self, event_id): + r"""Event Odds Summary + + :param `event_id`:(required),Event ID you get from events/*. + """ + params = { + 'event_id': event_id, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._event_odds_summary, params=params) + return json.loads(req.content) + + def event_odds(self, event_id, source=None, since_time=None, odds_market=None): + r"""Event Odds + + :param `event_id`:(required),Event ID you get from events/*. + :param `source`:(optional),bet365, 10bet, ladbrokes, williamhill, betclic, pinnaclesports, planetwin365, ysb88, 188bet, unibet, bwin, betfair, betfred, cloudbet, betsson, betdaq, paddypower, sbobet, titanbet, betathome, dafabet, marathonbet, betvictor, intertops, betredkings, interwetten, betway, 1xbet, nitrogensports, winner, betregal, skybet, marsbet. defaults to bet365. + :param `since_time`:(optional),Integer. add_time will be >= $since_time in results. Faster to get only updates. + :param `odds_market`:(optional),String. if you only need one (or few) market to save time/bandwidth, pass the related string like &odds_market=1 or &odds_market=2,3 etc. + """ + params = { + 'event_id': event_id, + 'token': self.token + } + + if source: + params['source'] = source + if since_time: + params['since_time'] = since_time + if odds_market: + params['odds_market'] = odds_market + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._event_odds, params=params) + return json.loads(req.content)['results'] + + def event_stats_trend(self, event_id): + r"""Event Stats Trend + requires "Soccer Enhanced API" permission,see [Pricing](https://betsapi.com/mm/pricing) for more details. + Soccer only. only available for events after 2017-06-10. + + :param `event_id`:(required),Event ID you get from events/*. + """ + params = { + 'event_id': event_id, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._event_stats_trend, params=params) + return json.loads(req.content) + + def event_lineup(self, event_id): + r"""Event Lineup + requires "Soccer Enhanced API" permission,see [Pricing](https://betsapi.com/mm/pricing) for more details. + Soccer only. Note not all events have lineup. you can get the flag (has_lineup) in /event/view. + + :param `event_id`:(required),Event ID you get from events/*. + """ + params = { + 'event_id': event_id, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._event_lineup, params=params) + return json.loads(req.content) + + def event_videos(self, event_id): + r"""Event Videos + NOTE: it's collected from Internet and not very reliable. The results might be wrong, USE IT at your own risk. + + :param `event_id`:(required),Event ID you get from events/*. + """ + params = { + 'event_id': event_id, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._event_videos, params=params) + return json.loads(req.content)['results'] + + def league(self, sport_id, cc=None, page=None): + r"""League + + :param sport_id:(required),see [R-SportID](https://betsapi.com/docs/GLOSSARY.html#r-sportid) for more details. + :param cc:(optional),Eg: 'co' for Colombia ([R-Countries](https://betsapi.com/docs/GLOSSARY.html#r-countries)). + :param page:(optional),[R-Pager](https://betsapi.com/docs/GLOSSARY.html#r-pager). + + """ + params = { + 'sport_id': sport_id, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._league, params=params) + return json.loads(req.content)['results'] + + def league_table(self, league_id): + r"""League Table + Note a few of (less than 5%) teams do not have 'id'. + + :param `league_id`:(required),flag 'has_leaguetable' from [League API](https://betsapi.com/docs/events/league_table.html#league). + """ + + params = { + 'league_id': league_id, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._league_table, params=params) + return json.loads(req.content)['results'] + + def league_toplist(self, league_id): + r"""League TopList + requires "Soccer Enhanced API" permission,see [Pricing](https://betsapi.com/mm/pricing) for more details. + Note a few of (less than 5%) teams do not have 'id'. + + :param `league_id`:(required),flag 'has_toplist' from [League API](https://betsapi.com/docs/events/league_toplist.html#league). + """ + params = { + 'league_id': league_id, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + + req = requests.get(self._league_toplist, params=params) + return json.loads(req.content) + + def team(self, sport_id, page=None): + r"""Team + + :prama `sport_id`:(required),see [R-SportID](https://betsapi.com/docs/GLOSSARY.html#r-sportid) for more details. + :prama `page`:(optional),see [R-Pager](https://betsapi.com/docs/GLOSSARY.html#r-pager) for more details. + """ + params = { + 'sport_id': sport_id, + 'token': self.token + } + + if page: + params['page'] = page + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._team, params=params) + return json.loads(req.content)['results'] + + def team_squad(self, team_id): + r"""Team Squad + requires "Soccer Enhanced API" permission,see [Pricing](https://betsapi.com/mm/pricing) for more details. + + :param `team_id`:(required),flag 'has_squad' from [Team API](https://betsapi.com/docs/events/team_squad.html#team). + """ + params = { + 'team_id': team_id, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._team_squad, params=params) + return json.loads(req.content) diff --git a/betsapi/results.py b/betsapi/results.py new file mode 100644 index 0000000..33eaf6d --- /dev/null +++ b/betsapi/results.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python +#-*-coding:utf-8-*- +import requests +import json +from .baseapi import BaseBetsAPI + +class Results(BaseBetsAPI): + r"""Results library. + """ + + def __init__(self, token): + self.token = token + + # English by default + self.LNG_ID = '1' + + self._betfred= 'https://api.betsapi.com/v1/betfred/result' + self._williamhill= 'https://api.betsapi.com/v1/williamhill/result' + self._sbobet= 'https://api.betsapi.com/v1/sbobet/result' + self._betsson= 'https://api.betsapi.com/v1/betsson/result' + + def betfred(self,event_id): + r"""BetFred Result + Note a few of (less than 2%) events are not covered. + Useful that you want the results by querying with BetFred XML Feed. + + :param `event_id`:(required),event_id from BetFred XML Feeds. (.20 will be removed automatically). + """ + params = { + 'event_id':event_id, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._betfred, params=params) + return json.loads(req.content) + + def williamhill(self,event_id ): + r"""WilliamHill Result + Note a few of (less than 2%) events are not covered. + Useful that you want the results by querying with WilliamHill XML Feed. + + :param `event_id`:(required),event_id from WilliamHill XML Feeds. (Example: the id 10901582 is from url http://sports.williamhill.com/bet/en-gb/betting/e/10901582/) + + """ + params = { + 'event_id':event_id, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._williamhill, params=params) + return json.loads(req.content) + + def sbobet(self, event_id): + r"""Sbobet Result + Note a few of (less than 2%) events are not covered. + Useful that you want the results by querying with Sbobet Event ID. + + :param `event_id`:(required),event_id from Sbobet. + """ + params = { + 'event_id':event_id, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._sbobet, params=params) + return json.loads(req.content) + + def betsson(self,event_id ): + r"""Betsson Result + Note a few of (less than 3%) events are not covered. + Useful that you want the results by querying with Betsson Event ID. + + :param `event_id`:(required),event_id from Betsson. + """ + params = { + 'event_id':event_id, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._betsson, params=params) + return json.loads(req.content) \ No newline at end of file diff --git a/betsapi/sbobet.py b/betsapi/sbobet.py new file mode 100644 index 0000000..467e630 --- /dev/null +++ b/betsapi/sbobet.py @@ -0,0 +1,101 @@ +#!/usr/bin/env python +#-*-coding:utf-8-*- +import requests +import json +from .baseapi import BaseBetsAPI + + +class Sbobet(BaseBetsAPI): + r"""Sbobet library. + """ + + def __init__(self, token): + self.token = token + + # English by default + self.LNG_ID = '1' + + self._inplay = 'https://api.betsapi.com/v1/sbobet/inplay' + self._upcoming = 'https://api.betsapi.com/v1/sbobet/upcoming' + self._event = 'https://api.betsapi.com/v1/sbobet/event' + self._result = 'https://api.betsapi.com/v1/sbobet/result' + + def inplay(self, sport_id=None,page=None): + r"""Sbobet InPlay + + :param `sport_id`:(optional),[R-SportID](https://betsapi.com/docs/GLOSSARY.html#r-sportid) (only 1-Soccer is supported now). + :param `page`:(optional),[R-Pager](https://betsapi.com/docs/GLOSSARY.html#r-pager). + """ + params = { + 'token': self.token + } + + if sport_id: + params['sport_id'] = sport_id + + if page: + params['page'] = page + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._inplay, params=params) + return json.loads(req.content) + + def upcoming(self, sport_id=None,day=None,page=None): + r"""Sbobet Upcoming + + :param `sport_id`:(optional),[R-SportID](https://betsapi.com/docs/GLOSSARY.html#r-sportid) (only 1-Soccer is supported now). + :param `day`:(optional),format YYYYMMDD, eg: 20161201. + :param `page`:(optional),[R-Pager](https://betsapi.com/docs/GLOSSARY.html#r-pager). + """ + params = { + 'token': self.token + } + + if sport_id: + params['sport_id'] = sport_id + if day: + params['day'] = day + if page: + params['page'] = page + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._upcoming, params=params) + return json.loads(req.content) + + def event(self, event_id): + r"""Sbobet Event + + :param `event_id`:(required),Event ID you get from /sbobet/inplay or upcoming. + """ + params = { + 'event_id': event_id, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._event,params=params) + return json.loads(req.content) + + def result(self, event_id): + r"""Sbobet Result + Note a few of (less than 2%) events are not covered. + + :param `event_id`:(required),Event Id from Sbobet API. + you can send multiple event_ids in one request with event_id=1,2,3,4 up to max 10 ids. + """ + params = { + 'event_id': event_id, + 'token': self.token + } + + if self.LNG_ID: + params['LNG_ID'] = self.LNG_ID + + req = requests.get(self._result, params=params) + return json.loads(req.content) \ No newline at end of file diff --git a/demo.py b/demo.py new file mode 100644 index 0000000..7192a7c --- /dev/null +++ b/demo.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python +#-*-coding:utf-8-*- + +from betsapi import * + +token = 'YOUR-TOKEN' +bet365api = Bet365(token) + +eventsapi = Events(token) + + +def main(): + inplay_soccer = bet365api.inplay_filter('1') + eventsapi.inplay_events('1') + + +if __name__ == '__main__': + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f229360 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +requests diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..224a779 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[metadata] +description-file = README.md \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..aca5c6e --- /dev/null +++ b/setup.py @@ -0,0 +1,27 @@ +import re +try: + from setuptools import setup +except ImportError: + from distutils.core import setup + +requires = ['requests'] + +version = '' +with open('betsapi/__init__.py', 'r') as fd: + version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', fd.read(), re.MULTILINE).group(1) +if not version: + raise RuntimeError('Cannot find version information') + +setup( + name='betsapi', + packages=['betsapi'], + version=version, + description='betsapi python SDK', + author='meoww', + author_email='i@meoww.app', + install_requires=requires, + url='https://github.com/qwqmeow/betsapi-python', + download_url='https://github.com/qwqmeow/betsapi-python/releases', + keywords=['bet', 'api', 'odds'], + classifiers=[], +)