def add_matches_to_db(odds, sport, site): """ :param odds: Cotes des matches :type odds: dict[str,int] :param sport: Sport :param site: Nom du bookmaker :return: Ajoute les équipes inconnues dans la base de données """ matches = odds.keys() teams = set( chain.from_iterable(list(map(lambda x: x.split(" - "), list(matches))))) teams = set(map(lambda x: x.strip(), teams)) teams_not_in_db_site = set() teams_sets = [] for team in teams: line = is_in_db_site(team, sport, site) if not line: teams_not_in_db_site.add(team) if not teams_not_in_db_site: return print(list(teams_not_in_db_site), site) i = 0 teams_sets.append(set()) for team in teams_not_in_db_site: line = is_in_db(team, sport, site) if line: success = add_name_to_db(line[0], team, site) if not success: teams_sets[i].add(team) else: teams_sets[i].add(team) print(i, list(teams_sets[i]), site) if not teams_sets[i]: return get_close_name_functions = [get_close_name, get_close_name2] if sport == "tennis": get_close_name_functions.append(get_close_name3) get_close_name_functions.append(get_double_team_tennis) for only_null in [True, False]: for get_close_name_function in get_close_name_functions: i += 1 teams_sets.append(set()) for team in teams_sets[i - 1]: lines = get_close_name_function( team, sport, site, only_null)[:3] #Pour éviter d'avoir trop de résultats if lines: for line in lines: success = add_name_to_db(line[0], team, site) if not success: teams_sets[i].add(team) else: teams_sets[i].add(team) print(i, list(teams_sets[i]), site) if not teams_sets[i]: return i += 1 teams_sets.append(set()) for team in teams_sets[i - 1]: future_opponents, future_matches = get_future_opponents( team, matches) success = False for future_opponent, future_match in zip( future_opponents, future_matches): id_opponent = get_id_by_site(future_opponent, sport, site) if id_opponent < 0: id_to_find = get_id_by_opponent_thesportsdb( id_opponent, future_match, odds) else: id_to_find = get_id_by_opponent( id_opponent, future_match, odds) if id_to_find: success = add_name_to_db(id_to_find, team, site) if success: break if not success: teams_sets[i].add(team) print(i, list(teams_sets[i]), site) if not teams_sets[i]: return
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 add_matches_to_db(odds, sport, site, id_competition): """ :param odds: Cotes des matches :type odds: dict[str,int] :param sport: Sport :param site: Nom du bookmaker :return: Ajoute les équipes inconnues dans la base de données """ matches = odds.keys() teams = set( chain.from_iterable(list(map(lambda x: x.split(" - "), list(matches))))) teams = set(map(lambda x: x.strip(), teams)) teams_sets = [] not_matching_teams = {} i = 0 teams_sets.append(set()) for team in teams: if not team: continue not_matching_teams[team] = [] line = is_in_db_site(team, sport, site) if not line: teams_sets[i].add(team) if not teams_sets[i]: return print(i, list(teams_sets[i]), site) get_close_name_functions = [ is_in_db, get_close_name, get_close_name2, get_close_name4 ] if sport == "tennis": get_close_name_functions.append(get_close_name3) get_close_name_functions.append(get_double_team_tennis) for only_null in [True, False]: for get_close_name_function in get_close_name_functions: i += 1 teams_sets.append(set()) for team in teams_sets[i - 1]: success = False lines = get_close_name_function( team, sport, site, only_null)[:3] #Pour éviter d'avoir trop de résultats for line in lines: if line[0] not in not_matching_teams[team]: check = not is_matching_next_match( id_competition, line[0], team, odds) date_next_match = datetime.datetime.today() try: date_next_match = sorted( [ odds[x] for x in odds.keys() if team in x.split(" - ") ], key=lambda x: x["date"])[0]["date"] except IndexError: pass date_next_match_db = get_time_next_match( id_competition, line[0]) success = add_name_to_db(line[0], team, site, check, date_next_match, date_next_match_db) if success: break not_matching_teams[team].append(line[0]) if not success: teams_sets[i].add(team) if len(teams_sets[i]) != len(teams_sets[i - 1]): print(i, list(teams_sets[i]), site) if not teams_sets[i]: return i += 1 teams_sets.append(set()) for team in teams_sets[i - 1]: future_opponents, future_matches = get_future_opponents( team, matches) success = False for future_opponent, future_match in zip( future_opponents, future_matches): id_opponent = get_id_by_site(future_opponent, sport, site) if id_opponent < 0: id_to_find = get_id_by_opponent_thesportsdb( id_opponent, future_match, odds) else: id_to_find = get_id_by_opponent( id_opponent, future_match, odds) if id_to_find and id_to_find not in not_matching_teams[ team]: check = not is_matching_next_match( id_competition, id_to_find, team, odds) date_next_match = sorted( [ odds[x] for x in odds.keys() if team in x.split(" - ") ], key=lambda x: x["date"])[0]["date"] date_next_match_db = get_time_next_match( id_competition, id_to_find) success = add_name_to_db(id_to_find, team, site, check, date_next_match, date_next_match_db) if success: break not_matching_teams[team].append(id_to_find) if not success: teams_sets[i].add(team) if len(teams_sets[i]) != len(teams_sets[i - 1]): print(i, list(teams_sets[i]), site) if not teams_sets[i]: return
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 add_matches_to_db(odds, sport, site): """ :param odds: Dictionnaire {match :{"date":date, "odds":cotes}} :param sport: Sport :param site: Nom du bookmaker :return: Ajoute les équipes inconnues dans la base de données """ matches = odds.keys() teams = set(chain.from_iterable(list(map(lambda x: x.split(" - "), list(matches))))) teams = set(map(lambda x: x.strip(), teams)) teams_not_in_db_site = set() teams_sets = [] for team in teams: line = is_in_db_site(team, sport, site) if not line: teams_not_in_db_site.add(team) if not teams_not_in_db_site: return print(list(teams_not_in_db_site)) i = 0 teams_sets.append(set()) for team in teams_not_in_db_site: line = is_in_db(team, sport, site) if line: success = add_name_to_db(line[0], team, site) if not success: teams_sets[i].add(team) else: teams_sets[i].add(team) print(i, list(teams_sets[i])) if not teams_sets[i]: return i += 1 teams_sets.append(set()) for only_null in [True, False]: for team in teams_sets[i - 1]: line = get_close_name(team, sport, site, only_null) if line: success = add_name_to_db(line[0], team, site) if not success: teams_sets[i].add(team) else: teams_sets[i].add(team) print(i, list(teams_sets[i])) if not teams_sets[i]: return i += 1 teams_sets.append(set()) for team in teams_sets[i - 1]: future_opponents, future_matches = get_future_opponents(team, matches) success = False for future_opponent, future_match in zip(future_opponents, future_matches): id_opponent = get_id_by_site(future_opponent, sport, site) if id_opponent < 0: id_to_find = get_id_by_opponent_thesportsdb(id_opponent, future_match, odds) else: id_to_find = get_id_by_opponent(id_opponent, future_match, odds) if id_to_find: success = add_name_to_db(id_to_find, team, site) if success: break if not success: teams_sets[i].add(team) print(i, list(teams_sets[i])) if not teams_sets[i]: return i += 1 teams_sets.append(set()) for team in teams_sets[i - 1]: line = get_close_name2(team, sport, site, only_null) if line: success = add_name_to_db(line[0], team, site) if not success: teams_sets[i].add(team) else: teams_sets[i].add(team) print(i, list(teams_sets[i])) if not teams_sets[i]: return i += 1 teams_sets.append(set()) for team in teams_sets[i - 1]: future_opponents, future_matches = get_future_opponents(team, matches) success = False for future_opponent, future_match in zip(future_opponents, future_matches): id_opponent = get_id_by_site(future_opponent, sport, site) if id_opponent < 0: id_to_find = get_id_by_opponent_thesportsdb(id_opponent, future_match, odds) else: id_to_find = get_id_by_opponent(id_opponent, future_match, odds) if id_to_find: success = add_name_to_db(id_to_find, team, site) if success: break if not success: teams_sets[i].add(team) print(i, list(teams_sets[i])) if not teams_sets[i]: return i += 1 teams_sets.append(set()) if sport == "tennis": for team in teams_sets[i - 1]: line = get_close_name3(team, sport, site, only_null) if line: success = add_name_to_db(line[0], team, site) if not success: teams_sets[i].add(team) else: teams_sets[i].add(team) print(i, list(teams_sets[i])) if not teams_sets[i]: return i += 1 teams_sets.append(set()) for team in teams_sets[i - 1]: future_opponents, future_matches = get_future_opponents(team, matches) found = False for future_opponent, future_match in zip(future_opponents, future_matches): id_opponent = get_id_by_site(future_opponent, sport, site) if id_opponent < 0: id_to_find = get_id_by_opponent_thesportsdb(id_opponent, future_match, odds) else: id_to_find = get_id_by_opponent(id_opponent, future_match, odds) if id_to_find: found = True success = add_name_to_db(id_to_find, team, site) if not success: teams_sets[i].add(team) if not found: teams_sets[i].add(team) print(i, list(teams_sets[i])) if not teams_sets[i]: return i += 1 teams_sets.append(set()) for team in teams_sets[i - 1]: line = get_double_team_tennis(team, site) if line: success = add_name_to_db(line[0], team, site) if not success: teams_sets[i].add(team) else: teams_sets[i].add(team) print(i, list(teams_sets[i])) if not teams_sets[i]: return i += 1 teams_sets.append(set()) for team in teams_sets[i - 1]: future_opponents, future_matches = get_future_opponents(team, matches) found = False for future_opponent, future_match in zip(future_opponents, future_matches): id_opponent = get_id_by_site(future_opponent, sport, site) if id_opponent < 0: id_to_find = get_id_by_opponent_thesportsdb(id_opponent, future_match, odds) else: id_to_find = get_id_by_opponent(id_opponent, future_match, odds) if id_to_find: success = add_name_to_db(id_to_find, team, site) if not success: teams_sets[i].add(team) if not found: teams_sets[i].add(team) print(i, list(teams_sets[i])) if not teams_sets[i]: return i += 1 teams_sets.append(set())
def get_sub_markets_players_basketball_parionssport(id_match): """ Get Parions Sport odds for sub-markets in basketball match """ if not id_match: return {} url = ( "https://www.enligne.parionssport.fdj.fr/lvs-api/ff/{}?originId=3&lineId=1&showMarketTypeGroups=true&ext=1" "&showPromotions=true".format(id_match)) req = requests.get(url, headers={'X-LVS-HSToken': get_parionssport_token()}) parsed = req.json() items = parsed["items"] markets_to_keep = { 'Performance du Joueur - Total Passes décisives': 'Passes', 'Performance du Joueur - Total Rebonds': 'Rebonds', 'Performance du Joueur - Total Points + Passes': 'Points + passes', 'Performance du Joueur - Total Points + Rebonds': 'Points + rebonds', 'Performance du Joueur - Total Rebonds + Passes': 'Passes + rebonds', 'Performance du joueur - Total Points (Supérieur à la valeur affichée)': 'Points', 'foo': '3 Points' } sub_markets = {v: defaultdict(list) for v in markets_to_keep.values()} for item in items: if not item.startswith("o"): continue odd = items[item] market = items[odd["parent"]] if not "desc" in market: continue is_3_pts = "(paniers à 3pts)" in market["desc"] if not market["desc"] in markets_to_keep and not is_3_pts: continue id_team = is_in_db_site(market["desc"].split(" - ")[-1], "basketball", "parionssport") if id_team: ref_player = get_formatted_name_by_id(id_team[0]) if not odd.get("price"): continue if "flags" in odd and "hidden" in odd["flags"]: continue if is_3_pts: limit = str(odd["spread"]) else: limit = odd["desc"].split()[-1].replace(",", ".") player = odd["desc"].split(" - ")[0].split("(")[0].strip() if player == odd["desc"]: player = odd["desc"].split("- ")[0].strip() ref_player = add_close_player_to_db(player, "parionssport") if is_player_added_in_db(player, "parionssport"): ref_player = is_player_added_in_db(player, "parionssport") elif not ref_player: if sb.DB_MANAGEMENT: print(player, "parionssport") continue key_player = (ref_player + "_" + limit).split(".5")[0] + ".5" key_market = markets_to_keep[ market["desc"]] if not is_3_pts else "3 Points" if key_player not in sub_markets[key_market]: sub_markets[key_market][key_player] = { "odds": { "parionssport": [] } } sub_markets[key_market][key_player]["odds"]["parionssport"].append( float(odd["price"].replace(",", "."))) if key_market == "Points": sub_markets[key_market][key_player]["odds"]["parionssport"].append( 1.01) for sub_market in sub_markets: sub_markets[sub_market] = dict(sub_markets[sub_market]) return sub_markets