Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.

Commit f58b0f3

Browse files
committed
first commit
1 parent 4d9e32f commit f58b0f3

15 files changed

Lines changed: 1244 additions & 2 deletions

.travis.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
language: python
2+
3+
python:
4+
- "2.7"
5+
- "3.4"
6+
7+
# command to install dependencies
8+
install: pip install -r requirements.txt
9+
10+
# command to run tests
11+
script: python demo.py
12+
13+
branches:
14+
only:
15+
- master

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
1-
# betsapi-python
2-
python SDK of betsapi
1+
## betsapi-python
2+
3+
python SDK of betsapi.com.
4+
betsapi.com is a excellent api for bet app.
5+
6+
## docs
7+
8+
https://betsapi.com/docs/
9+
10+
## gitbook
11+
12+
https://github.com/fayland/betsapi-gitbook
13+
14+
## translations
15+
16+
https://github.com/fayland/betsapi-translation/

betsapi/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
BetsAPI library
4+
"""
5+
__version__ = '1.0.0'
6+
7+
from .bet365 import Bet365
8+
from .betfair import Betfair
9+
from .betway import Betway
10+
from .bwin import BWin
11+
from .events import Events
12+
from .results import Results
13+
from .sbobet import Sbobet
14+
15+
__all__ = ("Bet365", "Betfair", "Betway","BWin","Events","Results","Sbobet")

betsapi/baseapi.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# -*- coding:utf-8 -*-
2+
3+
import os
4+
import sys
5+
import json
6+
import requests
7+
8+
9+
class BaseBetsAPI(object):
10+
11+
12+
def __init__(self):
13+
14+
self.token = None
15+
16+
17+
def build_uri(self, url, endpoint):
18+
r"""
19+
:param `url`:(required), url should not end with '/'.
20+
:param `endpoint`:(required),endpoint should not start with '/'.
21+
"""
22+
return '/'.join([url, endpoint])
23+
24+
def set_lng(self, lng_id):
25+
r"""set language.
26+
:param `lng_id`:(required),see [faq](https://betsapi.com/docs/events/faq.html) for more details.
27+
"""
28+
self.LNG_ID = str(lng_id)

betsapi/bet365.py

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#!/usr/bin/env python
2+
#-*-coding:utf-8-*-
3+
import json
4+
import os
5+
import re
6+
import sys
7+
8+
import requests
9+
10+
from .baseapi import BaseBetsAPI
11+
12+
13+
class Bet365(BaseBetsAPI):
14+
"""
15+
Bet365 library.
16+
"""
17+
18+
def __init__(self, token):
19+
r"""
20+
:param `token`: required.
21+
"""
22+
23+
self.token = token
24+
25+
# English by default
26+
self.LNG_ID = '1'
27+
28+
v1_bet365='https://api.betsapi.com/v1/bet365'
29+
30+
self._inplay= self.build_uri(v1_bet365,'inplay')
31+
self._inplay_filter = self.build_uri(v1_bet365,'inplay_filter')
32+
self._inplay_event= self.build_uri(v1_bet365,'event')
33+
self._upcoming_events= self.build_uri(v1_bet365,'upcoming')
34+
self._prematch_odds= self.build_uri(v1_bet365,'start_sp')
35+
self._result= self.build_uri(v1_bet365,'result')
36+
37+
38+
def inplay(self,raw=None):
39+
r"""Bet365 InPlay
40+
41+
:param `raw`:(optional),raw Bet365 body without parsing.
42+
"""
43+
params = {
44+
'token': self.token
45+
}
46+
47+
if raw:
48+
params['raw'] = raw
49+
50+
if self.LNG_ID:
51+
params['LNG_ID'] = self.LNG_ID
52+
53+
req = requests.get(self._inplay, params=params)
54+
return json.loads(req.content)
55+
56+
def inplay_filter(self,sport_id,league_id=None):
57+
r"""Bet365 InPlay Filter
58+
59+
:param `sport_id`:(required),see [R-SportID](https://betsapi.com/docs/GLOSSARY.html#r-sportid) for more details.
60+
:param `league_id`:(optional),useful when you want only one league.
61+
Note: there is no pager in this API call. we just return all events.
62+
"""
63+
params = {
64+
'sport_id':sport_id,
65+
'token': self.token
66+
}
67+
68+
if league_id:
69+
params['league_id'] = league_id
70+
71+
if self.LNG_ID:
72+
params['LNG_ID'] = self.LNG_ID
73+
74+
req = requests.get(self._inplay_filter, params=params)
75+
return json.loads(req.content)
76+
77+
def inplay_event(self,FI,stats=None,lineup=None,raw=None):
78+
r"""Bet365 Inplay Event
79+
80+
:param `FI`:(required),FI from Bet365 Inplay.
81+
:param `stats`: (optional),extra stats info (only provided for Soccer and Cricket).
82+
:param `lineup`:(optional),lineup info (only provided for Cricket right now).
83+
:param `raw`:(optional),raw Bet365 body without parsing.
84+
"""
85+
params = {
86+
'FI':FI,
87+
'token': self.token
88+
}
89+
90+
if stats:
91+
params['stats']=stats
92+
if lineup:
93+
params['lineup']=lineup
94+
if raw:
95+
params['raw']=raw
96+
97+
if self.LNG_ID:
98+
params['LNG_ID'] = self.LNG_ID
99+
100+
req = requests.get(self._inplay_event, params=params)
101+
return json.loads(req.content)
102+
103+
def upcoming_events(self,sport_id,league_id=None,day=None,page=None):
104+
r"""Bet365 Upcoming Events
105+
106+
:param `sport_id`:(required),see [R-SportID](https://betsapi.com/docs/GLOSSARY.html#r-sportid) for more details.
107+
:param `league_id`:(optional),useful when you want only one league.
108+
:param `day`:(optional),format YYYYMMDD, eg: 20161201.
109+
:param `page`:(optional),see [R-Pager](https://betsapi.com/docs/GLOSSARY.html#r-pager) for more details.
110+
"""
111+
params = {
112+
'sport_id':sport_id,
113+
'token': self.token
114+
}
115+
if league_id:
116+
params['league_id'] = league_id
117+
if day:
118+
params['day']= day
119+
if page:
120+
params['page'] = page
121+
122+
if self.LNG_ID:
123+
params['LNG_ID'] = self.LNG_ID
124+
125+
126+
req = requests.get(self._upcoming_events, params=params)
127+
return json.loads(req.content)['results']
128+
129+
def prematch_odds(self,FI,raw=None):
130+
r"""Bet365 PreMatch Odds
131+
132+
:param `FI`:(required),Event ID you get from bet365/upcoming.
133+
:param `raw`:(optional),raw Bet365 body without parsing.
134+
"""
135+
params = {
136+
'FI':FI,
137+
'token': self.token
138+
}
139+
140+
if raw:
141+
params['raw'] = raw
142+
143+
if self.LNG_ID:
144+
params['LNG_ID'] = self.LNG_ID
145+
146+
req = requests.get(self._prematch_odds, params=params)
147+
return json.loads(req.content)['results']
148+
149+
def result(self,event_id):
150+
r"""Bet365 Result
151+
152+
:param `event_id`:(required),Event ID (FI) from Bet365 Inplay.
153+
Note:you can send multiple event_ids in one request with event_id=1,2,3,4 up to max 10 ids.
154+
"""
155+
params = {
156+
'event_id':event_id,
157+
'token': self.token
158+
}
159+
160+
if self.LNG_ID:
161+
params['LNG_ID'] = self.LNG_ID
162+
163+
req = requests.get(self._result, params=params)
164+
return json.loads(req.content)

0 commit comments

Comments
 (0)