def get_odds_from_league_json(parsed_league, barrierebet): """ Get odds from league json """ bookmaker = "barrierebet" if barrierebet else "pasinobet" competitions = parsed_league["data"]["data"]["competition"] odds_league = {} for competition in competitions.values(): reversed_odds = competition["teams_reversed"] games = competition["game"] for game in games.values(): if "is_started" in game and game["is_started"]: continue if not game.get("team1_name") or not game.get("team2_name"): continue id = str(game["id"]) name = game["team1_name"].strip() + " - " + game["team2_name"].strip() date = datetime.datetime.fromtimestamp(game["start_ts"]) markets = game["market"] for market in markets.values(): odds = [] for event in sorted(market["event"].values(), key=lambda x: x["order"]): odds.append(event["price"]) if reversed_odds: name, odds = reverse_match_odds(name, odds) odds_league[name] = {"date":date, "odds":{bookmaker:odds}, "id":{bookmaker:id}} return odds_league
def parse_bwin(url): selenium_init.DRIVER["bwin"].maximize_window() selenium_init.DRIVER["bwin"].get(url) match_odds_hash = {} match = None date_time = None index_column_result_odds = 1 if "handball" in url else 0 is_sport_page = "/0" in url reversed_odds = False WebDriverWait(selenium_init.DRIVER["bwin"], 15).until( EC.presence_of_all_elements_located( (By.CLASS_NAME, "participants-pair-game")) or sportsbetting.ABORT) if sportsbetting.ABORT: raise sportsbetting.AbortException if is_sport_page: scroll(selenium_init.DRIVER["bwin"], "bwin", "grid-event-detail", 3, 'getElementById("main-view")') for _ in range(10): inner_html = selenium_init.DRIVER["bwin"].execute_script( "return document.body.innerHTML") soup = BeautifulSoup(inner_html, features="lxml") for line in soup.findAll(): if "class" in line.attrs and "grid-group" in line["class"]: strings = list(line.stripped_strings) if "Pari sur le vainqueur" in strings: index_column_result_odds = strings.index( "Pari sur le vainqueur") if "class" in line.attrs and "participants-pair-game" in line[ "class"]: match = " - ".join(list(line.stripped_strings)) reversed_odds = "@" in match match = format_bwin_names(match) if "class" in line.attrs and "starting-time" in line["class"]: date_time = format_bwin_time(line.text) if "class" in line.attrs and "grid-group-container" in line[ "class"]: if line.findChildren(attrs={"class": "grid-option-group"} ) and "Pariez maintenant !" not in list( line.stripped_strings): odds_line = line.findChildren( attrs={"class": "grid-option-group" })[index_column_result_odds] odds = [] for odd in list(odds_line.stripped_strings): try: odds.append(float(odd)) except ValueError: break if match: if reversed_odds: match, odds = reverse_match_odds(match, odds) match_odds_hash[match] = {} match_odds_hash[match]['odds'] = {"bwin": odds} match_odds_hash[match]['date'] = date_time match = None date_time = "undefined" if match_odds_hash: return match_odds_hash return match_odds_hash
def parse_bwin_api(parameter): """ Get Bwin odds from API """ token = get_bwin_token() if not token: return {} url = ( "https://cds-api.bwin.fr/bettingoffer/fixtures?x-bwin-accessid={}&lang=fr&country=FR&userCountry=FR" "&fixtureTypes=Standard&state=Latest&offerMapping=Filtered&offerCategories=Gridable&fixtureCategories=Gridable" "&{}&skip=0&take=1000&sortBy=Tags".format(token, parameter)) content = urllib.request.urlopen(url).read() parsed = json.loads(content) fixtures = parsed["fixtures"] odds_match = {} for fixture in fixtures: if fixture["stage"] == "Live": continue reversed_odds = " chez " in fixture["name"]["value"] odds = [] participants = fixture["participants"] name = " - ".join(map(lambda x: x["name"]["value"], participants)) games = fixture["games"] id = str(fixture["id"]) for game in games: odds_type = game["name"]["value"] if odds_type not in [ "1 X 2", "Pari sur le vainqueur (US)", "1X2 (temps réglementaire)", "Vainqueur 1 2" ]: continue for result in game["results"]: odds.append(result["odds"]) break date = truncate_datetime(dateutil.parser.isoparse( fixture["startDate"])) + datetime.timedelta(hours=2) if reversed_odds: name, odds = reverse_match_odds(name, odds) odds_match[name] = { "date": date, "odds": { "bwin": odds }, "id": { "bwin": id } } return odds_match
def parse_pasinobet(url): """ Retourne les cotes disponibles sur pasinobet """ selenium_init.DRIVER["pasinobet"].get("about:blank") selenium_init.DRIVER["pasinobet"].get(url) reversed_odds = "North%20America" in url match_odds_hash = {} match = None date_time = None WebDriverWait(selenium_init.DRIVER["pasinobet"], 15).until( EC.invisibility_of_element_located( (By.CLASS_NAME, "skeleton-line")) or sb.ABORT ) if sb.ABORT: raise sb.AbortException inner_html = selenium_init.DRIVER["pasinobet"].execute_script( "return document.body.innerHTML") soup = BeautifulSoup(inner_html, features="lxml") date = "" for line in soup.findAll(): if sb.ABORT: raise sb.AbortException if "class" in line.attrs and "category-date" in line["class"]: date = line.text.lower() date = date.replace("nov", "novembre") date = date.replace("déc", "décembre") date = date.replace("jan", "janvier") date = date.replace("fév", "février") date = date.replace("mar ", "mars ") if "class" in line.attrs and "event-header" in line["class"]: match = " - ".join(map(lambda x: list(x.stripped_strings)[0], line.findChildren("div", {"class": "teams-container-layout2"}))) time = line.findChild("div", {"class": "sbEventsList__time"}).text.strip() try: date_time = datetime.datetime.strptime(date+time, "%A, %d %B %Y%H:%M") except ValueError: date_time = "undefined" if "class" in line.attrs and "event-list" in line["class"]: if "---" not in list(line.stripped_strings): odds = list(map(float, line.stripped_strings)) if reversed_odds: match, odds = reverse_match_odds(match, odds) match_odds_hash[match] = {} match_odds_hash[match]["date"] = date_time match_odds_hash[match]["odds"] = {"pasinobet": odds} return match_odds_hash
def parse_bwin(url): """ Retourne les cotes disponibles sur bwin """ selenium_init.DRIVER["bwin"].maximize_window() selenium_init.DRIVER["bwin"].get(url) match_odds_hash = {} match = None date_time = None index_column_result_odds = 1 if "handball" in url else 0 is_sport_page = "/0" in url reversed_odds = False live = False WebDriverWait(selenium_init.DRIVER["bwin"], 15).until( EC.presence_of_all_elements_located( (By.CLASS_NAME, "participants-pair-game")) or sb.ABORT) if sb.ABORT: raise sb.AbortException if is_sport_page: scroll(selenium_init.DRIVER["bwin"], "bwin", "grid-event-detail", 3, 'getElementById("main-view")') for _ in range(10): inner_html = selenium_init.DRIVER["bwin"].execute_script( "return document.body.innerHTML") soup = BeautifulSoup(inner_html, features="lxml") for line in soup.findAll(): if "class" in line.attrs and "grid-group" in line["class"]: strings = list(line.stripped_strings) if "Pari sur le vainqueur" in strings: index_column_result_odds = strings.index( "Pari sur le vainqueur") if "class" in line.attrs and "participants-pair-game" in line[ "class"]: teams = [] if line.findChildren(attrs={"class": "participant-container"}): names_and_countries = list( line.findChildren( attrs={"class": "participant-container"})) for name_and_country in names_and_countries: strings = list(name_and_country.stripped_strings) if len(strings) == 2 and strings[1] != '@': teams.append(strings[0] + " (" + strings[1] + ")") else: teams.append(strings[0]) match = " - ".join(teams) reversed_odds = True if line.findChildren( attrs={"class": "away-indicator"}) else False if "class" in line.attrs and "starting-time" in line["class"]: date_time = format_bwin_time(line.text) if "class" in line.attrs and "live-icon" in line["class"]: live = True if "class" in line.attrs and "grid-group-container" in line[ "class"]: if (line.findChildren(attrs={"class": "grid-option-group"}) and "Pariez maintenant !" not in list( line.stripped_strings)): odds_line = line.findChildren( attrs={"class": "grid-option-group" })[index_column_result_odds] odds = [] for odd in list(odds_line.stripped_strings): try: odds.append(float(odd)) except ValueError: break if match: if reversed_odds: match, odds = reverse_match_odds(match, odds) if not live: match_odds_hash[match] = {} match_odds_hash[match]['odds'] = {"bwin": odds} match_odds_hash[match]['date'] = date_time else: live = False match = None date_time = "undefined" if match_odds_hash: return match_odds_hash return match_odds_hash