|
| 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