def get_sub_markets_players_basketball_unibet(id_match): if not id_match: return {} url = 'https://www.unibet.fr/zones/event.json?eventId=' + id_match content = requests.get(url).content parsed = json.loads(content) markets_class_list = parsed.get('marketClassList', []) markets_to_keep = { 'Performance du Joueur (Points + Rebonds + Passes)': 'Points + passes + rebonds', 'Nombre de passes du joueur': 'Passes', 'Nombre de rebonds du joueur': 'Rebonds', 'Performance du Joueur (Points + Passes)': 'Points + passes', 'Performance du Joueur (Points + Rebonds)': 'Points + rebonds', 'Performance du Joueur (Passes + Rebonds)': 'Passes + rebonds' } sub_markets = {v: defaultdict(list) for v in markets_to_keep.values()} for market_class_list in markets_class_list: market_name = market_class_list['marketName'] if market_name not in markets_to_keep: continue markets = market_class_list['marketList'] for market in markets: selections = market['selections'] for selection in selections: player = selection['name'].split(' - ')[0].split()[1] limit = selection['name'].split(' de ')[(-1)].replace(",", ".") price_up = int(selection['currentPriceUp']) price_down = int(selection['currentPriceDown']) odd = round(price_up / price_down + 1, 2) player = selection['name'].split(' - ')[0] ref_player = player if is_player_added_in_db(player, "unibet"): ref_player = is_player_added_in_db(player, "unibet") elif is_player_in_db(player): add_player_to_db(player, "unibet") else: if sb.DB_MANAGEMENT: print(player, "unibet") continue key_player = ref_player + "_" + limit key_market = markets_to_keep[market_name] if key_player not in sub_markets[key_market]: sub_markets[key_market][key_player] = { "odds": { "unibet": [] } } sub_markets[key_market][key_player]["odds"]["unibet"].insert( 0, odd) for sub_market in sub_markets: sub_markets[sub_market] = dict(sub_markets[sub_market]) return sub_markets
def get_sub_markets_players_basketball_pinnacle(id_match): if not id_match: return {} token = get_pinnacle_token() url_straight = "https://guest.api.arcadia.pinnacle.com/0.1/matchups/{}/markets/related/straight".format( id_match) url_related = "https://guest.api.arcadia.pinnacle.com/0.1/matchups/{}/related".format( id_match) req_straight = urllib.request.Request(url_straight, headers={'x-api-key': token}) req_related = urllib.request.Request(url_related, headers={'x-api-key': token}) content_straight = urllib.request.urlopen(req_straight).read() content_related = urllib.request.urlopen(req_related).read() all_odds = json.loads(content_straight) markets = json.loads(content_related) markets_to_keep = { 'PointsReboundsAssist': 'Points + passes + rebonds', 'Assists': 'Passes', 'Rebounds': 'Rebonds', 'Points': 'Points' } sub_markets = {v: defaultdict(list) for v in markets_to_keep.values()} for market in markets: if market.get("type") != "special": continue market_type = markets_to_keep.get(market["units"]) if not market_type: continue id_market = market["id"] player = market["special"]["description"].split("(")[0].strip() if "Total Points by" in player: player = player.split("Total Points by")[1].strip() ref_player = player if is_player_added_in_db(player, "pinnacle"): ref_player = is_player_added_in_db(player, "pinnacle") elif is_player_in_db(player): add_player_to_db(player, "pinnacle") else: if sb.DB_MANAGEMENT: print(player, "pinnacle") # add_new_player_to_db(player) continue odds, limit = get_pinnacle_odds_from_market_id(id_market, all_odds) if odds: key_player = ref_player + "_" + str(limit) sub_markets[market_type][key_player] = {"odds": {"pinnacle": odds}} for sub_market in sub_markets: sub_markets[sub_market] = dict(sub_markets[sub_market]) return sub_markets
def get_sub_markets_players_basketball_zebet(id_match): if not id_match: return {} url = 'https://www.zebet.fr/fr/event/' + id_match + '-' markets_to_keep = {'Nombre de passes décisives pour le joueur (prolongations incluses) ?':'Passes', 'Nombre de rebonds pour le joueur (prolongations incluses) ?':'Rebonds'} soup = BeautifulSoup((urllib.request.urlopen(url)), features='lxml') sub_markets = {v:defaultdict(list) for v in markets_to_keep.values()} market_name = None for line in soup.find_all(): if 'Zebet rencontre actuellement des difficultés techniques.' in line.text: raise sb.UnavailableSiteException if 'class' in line.attrs and 'bet-question' in line['class']: if line.text.strip() in markets_to_keep: market_name = line.text.strip() if market_name: if 'class' in line.attrs: if 'pmq-cote' in line['class']: odd = float(line.text.strip().replace(',', '.')) if 'class' in line.attrs and 'pmq-cote-acteur' in line['class']: plus = "+" in line.text player = re.split('\s[\-|\+]', line.text.strip())[0].split()[1].strip() limit = re.split('\s[\-|\+]', line.text.strip())[(-1)].strip().replace(",", ".") player = re.split('\s[\-|\+]', line.text.strip())[0].strip() ref_player = player if is_player_added_in_db(player, "zebet"): ref_player = is_player_added_in_db(player, "zebet") elif is_player_in_db(player): add_player_to_db(player, "zebet") else: if sb.DB_MANAGEMENT: print(player, "zebet") continue last = -1 key_player = ref_player + "_" + limit key_market = markets_to_keep[market_name] if key_player not in sub_markets[key_market]: sub_markets[key_market][key_player] = {"odds":{"zebet":[]}} if plus: sub_markets[key_market][key_player]["odds"]["zebet"].insert(0, odd) last = 0 else: sub_markets[key_market][key_player]["odds"]["zebet"].append(odd) if len(sub_markets[key_market][key_player]["odds"]["zebet"]) > 2: del sub_markets[key_market][key_player]["odds"]["zebet"][last] for sub_market in sub_markets: sub_markets[sub_market] = dict(sub_markets[sub_market]) return sub_markets
def get_sub_markets_players_basketball_betclic(id_match): if not id_match: return {} url = 'https://offer.cdn.betclic.fr/api/pub/v4/events/{}?application=2&countrycode=fr&language=fr&sitecode=frfr'.format( str(id_match)) content = urllib.request.urlopen(url).read() parsed = json.loads(content) if not parsed: return {} markets = parsed['markets'] sub_markets = {} markets_to_keep = { 'Bkb_Ppf2': 'Points + passes + rebonds', 'Bkb_Pta2': 'Passes', 'Bkb_Ptr2': 'Rebonds', 'Bkb_PnA': 'Points + passes', 'Bkb_PnR': 'Points + rebonds', 'Bkb_AeR': 'Passes + rebonds' } for market in markets: if market['mtc'] not in markets_to_keep: continue selections = market['selections'] odds_market = {} for selection in selections: player = re.split('\\s\\+\\s|\\s\\-\\s', selection['name'].replace(".", " "))[0].split()[1] limit = selection['name'].split(' de ')[(-1)].replace(",", ".") player = re.split('\\s\\+\\s|\\s\\-\\s', selection['name'].replace(".", " "))[0].strip() ref_player = player if is_player_added_in_db(player, "betclic"): ref_player = is_player_added_in_db(player, "betclic") elif is_player_in_db(player): add_player_to_db(player, "betclic") else: if sb.DB_MANAGEMENT: print(player, "betclic") continue key_player = ref_player + "_" + limit if key_player not in odds_market: odds_market[key_player] = {"odds": {"betclic": []}} odds_market[ref_player + "_" + limit]["odds"]["betclic"].append( selection['odds']) sub_markets[markets_to_keep[market['mtc']]] = dict(odds_market) return sub_markets
def get_sub_markets_players_basketball_winamax(id_match): """ Get submarkets odds from basketball match """ if not id_match: return {} url = 'https://www.winamax.fr/paris-sportifs/match/' + id_match try: req = urllib.request.Request(url) webpage = urllib.request.urlopen(req, timeout=10).read() soup = BeautifulSoup(webpage, features='lxml') except urllib.error.HTTPError: raise sb.UnavailableSiteException markets_to_keep = { '4436':'Points + passes + rebonds', '4437':'Passes', '4438':'Rebonds', '4971':'Points + passes + rebonds', '4970':'Passes', '4969':'Rebonds', '4442':'Points', '4968':'Points', '4434':'3 Points', '4433':'3 Points', '4432':'3 Points', '5423':'Points + rebonds', '5421':'Points + rebonds', '5424':'Points + passes', '5425':'Points + passes', '5426':'Passes + rebonds', '5427':'Passes + rebonds', } sub_markets = {v:defaultdict(list) for v in markets_to_keep.values()} for line in soup.find_all(['script']): if 'PRELOADED_STATE' not in str(line.string): continue json_text = line.string.split('var PRELOADED_STATE = ')[1].split(';var BETTING_CONFIGURATION')[0] if json_text[(-1)] == ';': json_text = json_text[:-1] dict_matches = json.loads(json_text) for bet in dict_matches['bets'].values(): if str(bet['betType']) not in markets_to_keep: continue id_team = is_in_db_site(bet['betTitle'].split(" par ")[-1], "basketball", "winamax") if id_team: ref_player = get_formatted_name_by_id(id_team[0]) limit = bet['specialBetValue'].split("sbv=")[-1].replace(",", ".") is_3_pts = bet['marketId'] in [9021, 9022] if bet["marketId"] == 9020: ref_player = "Match" is_3_pts = True id_outcomes = bet['outcomes'] for id_outcome in id_outcomes: odd = dict_matches['odds'][str(id_outcome)] if not is_3_pts: label = dict_matches['outcomes'][str(id_outcome)]['label'] code = dict_matches['outcomes'][str(id_outcome)]['code'] player = label.split(' - ')[0].split()[1] limit = code.split('_')[(-1)].replace(",", ".") player = label.split(' - ')[0].split('- Plus de ')[0].strip() ref_player = player if is_player_added_in_db(player, "winamax"): ref_player = is_player_added_in_db(player, "winamax") elif is_player_in_db(player): add_player_to_db(player, "winamax") else: if sb.DB_MANAGEMENT: print("nouveau joueur : ", player, "winamax") add_new_player_to_db(player) else: continue key_player = ref_player + "_" + limit key_market = markets_to_keep[str(bet['betType'])] if key_player not in sub_markets[key_market]: sub_markets[key_market][key_player] = {"odds":{"winamax":[]}} if not odd: odd = 1.01 sub_markets[key_market][key_player]["odds"]["winamax"].append(odd) if key_market == "Points": sub_markets[key_market][key_player]["odds"]["winamax"].append(1.01) for sub_market in sub_markets: sub_markets[sub_market] = dict(sub_markets[sub_market]) return dict(sub_markets)
def get_sub_markets_players_basketball_betclic(id_match): """ Get submarket odds from basketball match """ if not id_match: return {} url = ('https://offer.cdn.betclic.fr/api/pub/v4/events/{}?application=2&' 'countrycode=fr&language=fr&sitecode=frfr'.format(str(id_match))) req = requests.get(url) parsed = req.json() if not parsed: return {} markets = parsed['markets'] markets_to_keep = { 'Bkb_Ppf2': 'Points + passes + rebonds', 'Bkb_Pta2': 'Passes', 'Bkb_Ptr2': 'Rebonds', 'Bkb_PnA': 'Points + passes', 'Bkb_PnR': 'Points + rebonds', 'Bkb_AeR': 'Passes + rebonds', 'Bkb_20p': 'Points', 'Bkb_25p': 'Points', 'Bkb_30p': 'Points', 'Bkb_35p': 'Points', 'Bkb_40p': 'Points', 'BKB_3pt': '3 Points' } sub_markets = {v: defaultdict(list) for v in markets_to_keep.values()} for market in markets: if market['mtc'] not in markets_to_keep: continue is_points_market = market['mtc'][-1] == 'p' is_3_points = market['mtc'] == "BKB_3pt" selections = market['selections'] odds_market = {} for selection in selections: limit = "" if is_points_market: limit = str(int(market['mtc'].strip("Bkb_").strip('p')) - 0.5) else: limit = selection['name'].split(' de ')[(-1)].replace(",", ".") if is_3_points: ref_player = "Match" else: player = re.split('\\s\\+\\s|\\s\\-\\s', selection['name'].replace(".", " "))[0].strip() ref_player = player if is_player_added_in_db(player, "betclic"): ref_player = is_player_added_in_db(player, "betclic") elif is_player_in_db(player): add_player_to_db(player, "betclic") elif add_close_player_to_db(player, "betclic"): ref_player = is_player_added_in_db(player, "betclic") else: if sb.DB_MANAGEMENT: print(player, "betclic") continue key_player = ref_player + "_" + limit if key_player not in odds_market: odds_market[key_player] = {"odds": {"betclic": []}} odds_market[ref_player + "_" + limit]["odds"]["betclic"].append( selection['odds']) if is_points_market: odds_market[ref_player + "_" + limit]["odds"]["betclic"].append(1.01) sub_markets[markets_to_keep[market['mtc']]] = { **dict(odds_market), **sub_markets[markets_to_keep[market['mtc']]] } return sub_markets
def get_sub_markets_players_basketball_winamax(id_match): if not id_match: return {} url = 'https://www.winamax.fr/paris-sportifs/match/' + id_match try: req = urllib.request.Request(url, headers={'User-Agent': sb.USER_AGENT}) webpage = urllib.request.urlopen(req, timeout=10).read() soup = BeautifulSoup(webpage, features='lxml') except urllib.error.HTTPError: raise sb.UnavailableSiteException markets_to_keep = { '9017': 'Points + passes + rebonds', '9016': 'Passes', '9015': 'Rebonds', '9007': 'Points + passes + rebonds', '9006': 'Passes', '9005': 'Rebonds' } sub_markets = {v: defaultdict(list) for v in markets_to_keep.values()} for line in soup.find_all(['script']): if 'PRELOADED_STATE' not in str(line.string): continue json_text = line.string.split('var PRELOADED_STATE = ')[1].split( ';var BETTING_CONFIGURATION')[0] if json_text[(-1)] == ';': json_text = json_text[:-1] dict_matches = json.loads(json_text) for bet in dict_matches['bets'].values(): if str(bet['marketId']) not in markets_to_keep: continue id_outcomes = bet['outcomes'] for id_outcome in id_outcomes: label = dict_matches['outcomes'][str(id_outcome)]['label'] code = dict_matches['outcomes'][str(id_outcome)]['code'] player = label.split(' - ')[0].split()[1] limit = code.split('_')[(-1)].replace(",", ".") odd = dict_matches['odds'][str(id_outcome)] player = label.split(' - ')[0].split('- Plus de ')[0].strip() ref_player = player if is_player_added_in_db(player, "winamax"): ref_player = is_player_added_in_db(player, "winamax") elif is_player_in_db(player): add_player_to_db(player, "winamax") else: if sb.DB_MANAGEMENT: print(player, "winamax") continue key_player = ref_player + "_" + limit key_market = markets_to_keep[str(bet['marketId'])] if key_player not in sub_markets[key_market]: sub_markets[key_market][key_player] = { "odds": { "winamax": [] } } sub_markets[key_market][key_player]["odds"]["winamax"].append( odd) for sub_market in sub_markets: sub_markets[sub_market] = dict(sub_markets[sub_market]) return dict(sub_markets)
def get_sub_markets_players_basketball_unibet(id_match): if not id_match: return {} url = 'https://www.unibet.fr/zones/event.json?eventId=' + id_match content = requests.get(url).content parsed = json.loads(content) markets_class_list = parsed.get('marketClassList', []) markets_to_keep = { 'Performance du Joueur (Points + Rebonds + Passes)': 'Points + passes + rebonds', 'Nombre de passes du joueur': 'Passes', 'Nombre de rebonds du joueur': 'Rebonds', 'Performance du Joueur (Points + Passes)': 'Points + passes', 'Performance du Joueur (Points + Rebonds)': 'Points + rebonds', 'Performance du Joueur (Passes + Rebonds)': 'Passes + rebonds', "Joueur marquant 20 points ou plus": "Points", "Joueur marquant 25 points ou plus": "Points", "Joueur marquant 30 points ou plus": "Points", "Joueur marquant 35 points ou plus": "Points", "Joueur marquant 40 points ou plus": "Points", "Equipe à domicile - Nombre de 3 points marqués": "3 Points", "Equipe à l'exterieur - Nombre de 3 points marqués": "3 Points" } sub_markets = {v: defaultdict(list) for v in markets_to_keep.values()} for market_class_list in markets_class_list: market_name = market_class_list['marketName'] if market_name not in markets_to_keep: continue markets = market_class_list['marketList'] for market in markets: id_team = is_in_db_site( market.get("event{}Name".format( market["marketType"].split(" - ")[0].replace(" ", ""))), "basketball", "unibet") if id_team: ref_player = get_formatted_name_by_id(id_team[0]) is_3_pts = "Nombre de 3 points marqués" in market["marketName"] selections = market['selections'] for selection in selections: price_up = int(selection['currentPriceUp']) price_down = int(selection['currentPriceDown']) odd = round(price_up / price_down + 1, 2) limit = selection['name'].split(' de ')[(-1)].replace(",", ".") plus = "Plus de" in selection['name'] if not is_3_pts: player = selection['name'].split(' - ')[0] ref_player = player if is_player_added_in_db(player, "unibet"): ref_player = is_player_added_in_db(player, "unibet") elif is_player_in_db(player): add_player_to_db(player, "unibet") else: if sb.DB_MANAGEMENT: print(player, "unibet") add_new_player_to_db(player) else: continue key_market = markets_to_keep[market_name] if key_market == "Points": limit = str(float(market_name.split()[2]) - 0.5) key_player = ref_player + "_" + limit if key_player not in sub_markets[key_market]: sub_markets[key_market][key_player] = { "odds": { "unibet": [] } } if plus: sub_markets[key_market][key_player]["odds"][ "unibet"].insert(0, odd) else: sub_markets[key_market][key_player]["odds"][ "unibet"].append(odd) if key_market == "Points": sub_markets[key_market][key_player]["odds"][ "unibet"].append(1.01) for sub_market in sub_markets: sub_markets[sub_market] = dict(sub_markets[sub_market]) return sub_markets
def get_sub_markets_players_basketball_pmu(id_match): if not id_match: return {} url = 'https://mobile.parier.pmu.fr/PMU-Webkit/page/sportif/match?matchId=' + id_match markets_to_keep = {'Passes décisives':'Passes', 'Rebonds':'Rebonds', 'Joueur(s) qui marque(nt) 20 points ou plus':'Points', 'Joueur(s) qui marque(nt) 25 points ou plus':'Points', 'Joueur(s) qui marque(nt) 30 points ou plus':'Points', 'Joueur(s) qui marque(nt) 35 points ou plus':'Points', 'Joueur(s) qui marque(nt) 40 points ou plus':'Points' } soup = BeautifulSoup((urllib.request.urlopen(url)), features='lxml') sub_markets = {v:defaultdict(list) for v in markets_to_keep.values()} market_name = None odds = [] is_perf = False for parent in soup.find_all(): if 'class' in parent.attrs and 'market' in parent["class"]: market_title = parent.text.strip() is_perf = any([x in market_title for x in ['Rebonds', 'Passes décisives', "Joueur(s) qui marque"]]) is_points_market = "Joueur(s) qui marque" in market_title if is_points_market: limit = str(int(market_title.split("marque(nt) ")[1].split(" points")[0])-0.5) continue if not is_perf or 'class' not in parent.attrs or 'market-betting-options' not in parent["class"]: continue if not is_points_market: for line in parent.findChildren(): player, market_limit = market_title.split(' - ') try: market_name, limit = market_limit.split(" (") except ValueError: continue limit = limit.strip(")") if market_name and 'class' in line.attrs and 'odd' in line['class']: odds.append(float(line.text.strip().replace(",", "."))) if not market_name: continue ref_player = player if is_player_added_in_db(player, "pmu"): ref_player = is_player_added_in_db(player, "pmu") elif is_player_in_db(player): add_player_to_db(player, "pmu") else: if sb.DB_MANAGEMENT: print(player, "pmu") continue sub_markets[markets_to_keep[market_name]][ref_player + "_" + limit] = {"odds":{"pmu":list(reversed(odds))}} market_name = None odds = [] else: for line in parent.findChildren(): players = list(line.stripped_strings)[::2] odds = list(line.stripped_strings)[1::2] for player, odd in zip(players, odds): if odd == "SUSP": continue ref_player = player if is_player_added_in_db(player, "pmu"): ref_player = is_player_added_in_db(player, "pmu") elif is_player_in_db(player): add_player_to_db(player, "pmu") else: if sb.DB_MANAGEMENT: print(player, "pmu") continue sub_markets['Points'][ref_player + "_" + limit] = {"odds":{"pmu":[float(odd.replace(",", ".")), 1.01]}} market_name = None odds = [] break # try: # market_name, limit = market_limit.split(" (") # except ValueError: # continue # limit = limit.strip(")") # if market_name and 'class' in line.attrs and 'odd' in line['class']: # odds.append(float(line.text.strip().replace(",", "."))) for sub_market in sub_markets: sub_markets[sub_market] = dict(sub_markets[sub_market]) return sub_markets