def parse_1x2_button(row): # Find bet price and size bet_buttons = row.find('td', class_='coupon-runners').find_all('span') bets = [button.text if button.text[0] != '€' else button.text[1:] for button in bet_buttons] return {'1': BetPrice(*map(float, bets[:4])), 'x': BetPrice(*map(float, bets[4:8])), '2': BetPrice(*map(float, bets[8:12]))}
def parse_12_button(row): # Find odds odds_div = row.find('div', class_='odds') if not odds_div: return {} odds = odds_div.find_all('label') # Find liquidity liquidity = row.find('div', class_='odds').find_all('span') # print(liquidity) # print(odds) if not (odds and len(odds) == 4 and liquidity and len(liquidity) == 6): return {} return { '1': BetPrice(float(odds[0].text), float(liquidity[1].text[:-1]), float(odds[2].text), float(liquidity[4].text[:-1])), '2': BetPrice(float(odds[1].text), float(liquidity[2].text[:-1]), float(odds[3].text), float(liquidity[5].text[:-1])) }
def parse_uo_button(row): # Find odds odds_div = row.find('div', class_='odds') if not odds_div: return {} odds = odds_div.find_all('label') # Find liquidity liquidity = row.find('div', class_='odds').find_all('span') if not (odds and len(odds) == 4 and liquidity and len(liquidity) == 6): return {} # Convert strings to numbers try: odds = list(map(lambda x: float(x.text), odds)) liquidity = list(map(lambda x: float(x.text[:-1]), liquidity)) except ValueError: # If any of these is not numeric return an empty dict return {} return { 'u': BetPrice(odds[0], liquidity[1], odds[2], liquidity[4]), 'o': BetPrice(odds[1], liquidity[2], odds[3], liquidity[5]) }
def parse_1x2_button(row): # Find odds odds_div = row.find('div', class_='odds') if not odds_div: return {} odds = odds_div.find_all('label') # Find liquidity liquidity = row.find('div', class_='odds').find_all('span') if not (odds and len(odds) == 6 and liquidity and len(liquidity) == 8): return {} try: return { '1': BetPrice(float(odds[0].text), float(liquidity[1].text[:-1]), float(odds[3].text), float(liquidity[5].text[:-1])), 'x': BetPrice(float(odds[1].text), float(liquidity[2].text[:-1]), float(odds[4].text), float(liquidity[6].text[:-1])), '2': BetPrice(float(odds[2].text), float(liquidity[3].text[:-1]), float(odds[5].text), float(liquidity[7].text[:-1])) } except ValueError: return {}