def generate_best_odds(self): for key, value in vars(self.arguments).iteritems(): if isinstance(value, bool) and value: sport = key.upper() # Initialize the driver driver = Driver() # Login driver.login(config.SPORT[sport]['URL']) # Initialize the Sport class sport_class = Sport(sport, self.arguments.percentage) sport_class.get_data(driver.driver) """
def get_sport_bets(self, sport_name): """ Scrapes betting data for a given sport type :param sport_name: sport type to scrape betting data for :type sport_name: str """ sport_bets = [] tournaments = self.get_tournaments(sport_name) # tournaments = [tournaments[0]] for tournament in tournaments: print('tournament', tournaments.index(tournament) + 1, '/', len(tournaments)) self.renderer.get(tournament) matches = self.get_matches_from_tournament() for match in matches: print(' ' * 3, 'match', matches.index(match) + 1, '/', len(matches)) match_bets = self._get_bets(match) if match_bets: sport_bets.append(match_bets) break sport = Sport(sport_name, sport_bets) return sport
def get_live_matches_info_sport(self, sport_name): matches = [] self.renderer.get(self._LIVE_URL) events = [] events_ = [1, 2] time.sleep(2) while len(events) != len(events_): events = [] events_ = None menu = self.renderer.find_element_by_class_name('sportslist') list_of_sports = menu.find_elements_by_class_name('sprt') sport = None for _sport in list_of_sports: if _sport.find_element_by_class_name( 'sprtnm').text == self._ICONS[sport_name]: sport = _sport break events_ = sport.find_elements_by_class_name('sp-mn-ev') for el in events_: try: events.append(el.find_element_by_tag_name('div')) except Exception: pass print(len(events_), len(events)) for event in events: try: matches.append(self.get_live_match_basic_data(event)) except Exception: pass return Sport(sport_name, matches)
def get_all_bets_sport(self) -> Sport: all_matches = [] for sport in self.sports: all_matches += sport.matches self.all_matches_sport = Sport(self.sports[0].name, all_matches) self._scrape_bets() return self.all_matches_sport
def format_match(self, match): # print(match.title.similarities) # print(match.title.raw_teams) # print(match.title.teams) match = self.apply_unified_syntax_formatting(Sport('', [match])).matches[0] self._format_bet_titles_teams(match) return match
def _get_sports_from_sample_data(self): sports = [] path = os.path.abspath(os.path.dirname(__file__)).replace( 'arbitrager', 'scrapers\\sample_data\\{}\\'.format(self.sport_name)) for scraper in registry: sports.append(Sport.deserialize(path + scraper.get_name())) return sports
def get_matches_info_sport(self, sport_name): championships = self._get_championships(sport_name) championship_urls = OneXBetScraper.get_championship_urls(championships) print(len(championship_urls)) match_elements = self._get_match_elements(championships) sport_matches = self._get_matches_info(match_elements, championship_urls) sport = Sport(sport_name, sport_matches) return sport
def get_live_matches_info_sport(self, sport_name): matches = [] tournaments = self.get_live_tournaments(sport_name) print(self._NAME, 'scraping', len(tournaments), 'tournaments') # tournaments = [tournaments[0]] for tournament in tournaments: self.renderer.get(tournament) print(' ', tournaments.index(tournament) + 1) events = self.get_live_matches_from_tournament() for event in events: matches.append(self._get_live_match_basic_data(event)) return Sport(sport_name, matches)
def _get_bets_one_by_one(self, sport_name): sport_bets = [] matches = self.get_matches_info_sport(sport_name).matches for match in matches: print('match', matches.index(match) + 1, '/', len(matches)) print(match.date) match_bets = self.scrape_match_bets(match) if match_bets: sport_bets.append(match_bets) break sport = Sport(sport_name, sport_bets) return sport
def get_matches_info_sport(self, sport_name): sport_matches = [] championship_urls = self.get_championship_urls(sport_name) for championship_url in championship_urls[:]: if 'statistika' in championship_url: continue full_url = self._BASE_URL + championship_url championship_matches = self._get_championship_matches_info( full_url) sport_matches += championship_matches sport = Sport(sport_name, sport_matches) return sport
def get_matches_info_sport(self, sport_name): matches = [] subsections = self.get_subsections(sport_name) for subsection in subsections: tournaments = self.get_subsection_tournaments(subsection) time.sleep(1) print('favorit subsection:', subsections.index(subsection) + 1) for tournament in tournaments: events = tournament.find_elements_by_class_name( 'event--head-block') for event in events: matches.append(self._get_match_basic_data(event)) # break self.renderer.click(subsection) time.sleep(1) return Sport(sport_name, matches)
def get_sport_bets(self, sport_name): """ Scrapes betting data for a given sport type :param sport_name: sport type to scrape betting data for :type sport_name: str """ sport_bets = [] match_urls = self.get_match_urls(self, sport_name) # match_urls = match_urls[:20] for url in match_urls: print(' match', match_urls.index(url) + 1, '/', len(match_urls)) match_bets = self._get_bets_from_url(url) if match_bets: sport_bets.append(match_bets) break sport = Sport(sport_name, sport_bets) return sport
def get_sport_bets(self, sport_name): """ Scrapes betting data for a given sport type :param sport_name: sport type to scrape betting data for :type sport_name: str """ sport_bets = [] subsections = self.get_subsections(sport_name) # subsections = [subsections[6]] for subsection in subsections: print('subsection', subsections.index(subsection) + 1, '/', len(subsections)) tournaments = self.get_subsection_tournaments(subsection) for tournament in tournaments: print(' ' * 1, 'tournament', tournaments.index(tournament) + 1, '/', len(tournaments)) events = self.get_events_from_tournament(tournament) for event in events: print(' ' * 4, 'match', events.index(event) + 1, '/', len(events)) match_bets = self._get_bets(event) if match_bets: sport_bets.append(match_bets) break break self.renderer.click(subsection) time.sleep(1) sport = Sport(sport_name, sport_bets) return sport
def get_matches_info_sport(self, sport_name): matches = [] subsections = self.get_tournaments(sport_name) for subsection in subsections: # if not LIVE: try: self.renderer.click(subsection) except StaleElementReferenceException: continue # print(' ', subsections.index(subsection) + 1) time.sleep(2) events = self.renderer.find_elements_by_class_name( 'sportEventRow__body___3Ywcg') time.sleep(2) for event in events: try: event.find_element_by_class_name( 'matchDateTime__isLive___8f4IP') continue # match is live except NoSuchElementException: pass except StaleElementReferenceException: continue date_text = event.find_element_by_class_name( 'matchDateTime__date___2Hw-c').text teams_webel = event.find_elements_by_class_name( '__app-LogoTitle-wrapper') teams = [el.text for el in teams_webel] url = teams_webel[0].find_element_by_tag_name( 'a').get_attribute('href') date = DateTime.from_ggbet_str(date_text) matches.append(Match(MatchTitle(teams), url, date, self)) # if not LIVE: self.renderer.click(subsection) print(len(matches)) return Sport(sport_name, matches)
def test_parimatch_unified_syntax_formatting(self): sport = Sport.from_dict(self.parimatch_dota_dict) sport = self.parimatch_syntax_formatter.apply_unified_syntax_formatting( sport) self._test_unified_syntax_formatting(sport)
from groupers.esports.esports_fork_grouper import EsportsForkGrouper class LoLForkGrouper(EsportsForkGrouper): _grouped_by = { r'(^\d-(st|nd|rd|th) map: )?(total (kills|dragons|barons|turrets|inhibitors)|duration) (over|under) (\d+(' r'\.\d)?)$': (3, 6), r'(^\d-(st|nd|rd|th) map: )?(total kills) (even|odd)$': (3, ), r'(^\d-(st|nd|rd|th) map: ).+? (most kills)$': (3, ), r'(^\d-(st|nd|rd|th) map: ).+? (will first (kill (baron|dragon)|destroy (turret|inhibitor)))$': (3, ), r'(^\d-(st|nd|rd|th) map: ).+? (first blood|will make kill \d+)$': (3, ), r'(^\d-(st|nd|rd|th) map: ).+? (will first make \d+ kills)$': (3, ), } def _get_grouped_by(self) -> dict: result = dict(LoLForkGrouper._grouped_by) result.update(EsportsForkGrouper._get_grouped_by(self)) return result def _get_handicap_targets(self): return EsportsForkGrouper._get_handicap_targets(self) + ['kills'] if __name__ == '__main__': grouper = LoLForkGrouper() lol = Sport.from_dict(favorit_lol_dict) grouped_lol = grouper.group_bets(lol) print(grouped_lol)
return formatted_title def _format_first_kill(self): formatted_title = self.bet_title.lower() if 'first blood' in formatted_title: formatted_title = formatted_title.replace('1st team to ', '') formatted_title = formatted_title.replace(' first blood', '') formatted_title += ' first blood' return formatted_title def _format_map_duration(self): formatted_title = self.bet_title.lower() if 'map duration' in formatted_title: formatted_title = formatted_title.replace('map duration', 'duration') formatted_title = formatted_title.replace(' minutes', '') return formatted_title def _format_teams(self): formatted_title = self._move_teams_left() return formatted_title if __name__ == '__main__': formatter = DotaMarathonSyntaxFormatter() sport = Sport.from_dict(marathon.sport) formatted_sport = formatter.apply_unified_syntax_formatting(sport) print(formatted_sport) my_path = os.path.abspath(os.path.dirname(__file__)) path = my_path + '\\sample_data\\marathon.py' with open(path, 'w', encoding='utf-8') as f: print('sport =', formatted_sport, file=f)
def test_one_x_bet_unified_syntax_formatting(self): sport = Sport.from_dict(self.one_x_bet_lol_dict) sport = self.one_x_bet_syntax_formatter.apply_unified_syntax_formatting( sport) self._test_unified_syntax_formatting(sport)
def test_ggbet_unified_syntax_formatting(self): sport = Sport.from_dict(self.ggbet_csgo_dict) sport = self.ggbet_syntax_formatter.apply_unified_syntax_formatting( sport) self._test_unified_syntax_formatting(sport)
def get_name(self): return '1xbet' if __name__ == '__main__': grouper = CSGOForkGrouper() csgo = Sport('csgo', [ Match( MatchTitle(['Top Esports', 'Suning Gaming']), 'https://1x-bet.com/en/line/Esports/1309773-League-of-Legends-LPL-Summer-Playoffs/81469989-Top-Esports-Suning-Gaming/', DateTime(2020, 8, 9, 19, 0, 0), OneXBetScraper(), []), Match(MatchTitle(['Top', 'Sunning']), 'https://www.parimatch.com/en/sport/kibersport/liga-legend-lpl', DateTime(2020, 8, 9, 19, 0, 0), ParimatchScraper(), []), Match( MatchTitle(['Top Esports', 'SN Gaming']), 'https://www.favorit.com.ua/en/bets/#event=27802672&tours=182350,776347,776418,792747,977780,1011803,1037535,1061879,1258082,1265594,1293917,1618224,1713907,2270463', DateTime(2020, 8, 9, 19, 0, 0), FavoritScraper(), []), Match( MatchTitle(['Suning Gaming', 'Top Esports']), 'https://www.marathonbet.com/en/betting/e-Sports/LoL/LPL+Summer/Main+Event/Best+of+5+maps/Suning+Gaming+vs+Top+Esports+-+9994779', DateTime(2020, 8, 9, 19, 0, 0), MarathonScraper(), []), Match( MatchTitle(['Top Esports', 'Suning Gaming']), 'https://gg.bet/en/betting/match/top-esports-vs-suning-gaming-22-08', DateTime(2020, 8, 9, 19, 0, 0), GGBetScraper(), []), ]) groups = grouper.get_match_groups(csgo) pprint(groups)
return formatted_title def _format_first_to_win_number_of_rounds(self): formatted_title = self.bet_title.lower() if 'race to rounds' in formatted_title: formatted_title = formatted_title.replace('race to rounds ', '') words = re.split(' ', formatted_title) formatted_title = '' for i in range(0, len(words) - 1): formatted_title += words[i] + ' ' formatted_title += 'will be first to win ' + words[-1] + ' rounds' return formatted_title def _format_handicap(self): formatted_title = GSF._format_handicap(self) if 'handicap' in formatted_title and ' maps' not in formatted_title: formatted_title += ' rounds' return formatted_title if __name__ == '__main__': formatter = CSGOGGBetSyntaxFormatter() sport = Sport.from_dict(ggbet.sport) formatted_sport = formatter.apply_unified_syntax_formatting(sport) print(formatted_sport) my_path = os.path.abspath(os.path.dirname(__file__)) path = my_path + '\\sample_data\\ggbet.py' with open(path, 'w', encoding='utf-8') as f: print('sport =', formatted_sport, file=f)
def test_favorit_unified_syntax_formatting(self): sport = Sport.from_dict(self.favorit_dota_dict) sport = self.favorit_syntax_formatter.apply_unified_syntax_formatting( sport) self._test_unified_syntax_formatting(sport)
def test_marathon_unified_syntax_formatting(self): sport = Sport.from_dict(self.marathon_dota_dict) sport = self.marathon_syntax_formatter.apply_unified_syntax_formatting( sport) self._test_unified_syntax_formatting(sport)
def __init__(self, sport=None, rules=None): self._sport = Sport(sport) self._rules = rules self.name = None
return formatted_title def _format_map_duration(self): formatted_title = self.bet_title.lower() if 'map duration' in formatted_title: formatted_title = formatted_title.replace('map duration', 'duration') formatted_title = formatted_title.replace(' minutes', '') return formatted_title def _format_first_to_destroy(self): formatted_title = self.bet_title.lower() if 'which team will be the first to lose a turret?' in formatted_title: formatted_title = formatted_title.replace('which team will be the first to lose a turret?', 'will first destroy turret') formatted_title = self.swap_teams(formatted_title) return formatted_title def _format_teams(self): return self._move_teams_left() if __name__ == '__main__': formatter = LoLFavoritSyntaxFormatter() sport = Sport.from_dict(favorit.sport) formatted_sport = formatter.apply_unified_syntax_formatting(sport) print(formatted_sport) my_path = os.path.abspath(os.path.dirname(__file__)) path = my_path + '\\sample_data\\favorit.py' with open(path, 'w', encoding='utf-8') as f: print('sport =', formatted_sport, file=f)
if __name__ == "__main__": from enum import Enum from sport import Sport from collections import OrderedDict sports = Enum('sports', 'AJEDREZ ATLETISMO BALONCESTO FÚTBOL KARATE NATACIÓN VOLLEYBALL FLAG PINGPONG OTROS') sport = Sport(sports) people = range(0, 10) print("[[ Encuesta - Deportes populares ]]") for person in people: print("\nEncuestado #%s" % (person + 1)) print("Seleccione su deporte favorito\n") for s in sports: print("%s. %s" % (s.value, s.name)) choice = input("\n[1-%s] " % len(sports)) sport.upFav(sport.findById(int(choice))) # Implemento una instancia de dict con la ayuda de la clase OrderedDict. Este dict cuenta con los deportes # ordenados del mas popular al menos popular. favSportsDesc = OrderedDict(sorted(sport.__dict__.items(), key=lambda k: k[1]['favorites'], reverse=True)) print("\n[[ Resultado ]]") print("%s encuentados opinan que los deportes populares son: \n" % len(people)) for sk in favSportsDesc: print(str(sk).capitalize(), "(%s votos)" % favSportsDesc[sk]['favorites'])
formatted_title = self.bet_title.lower() formatted_title = ' '.join(formatted_title.split()) formatted_title = formatted_title.strip() return formatted_title def _format_after(self, bets): return bets def _format_teams(self): return self._move_teams_left() def _format_uncommon_chars(self): formatted_title = self.bet_title.lower() # these are different characters :) formatted_title = formatted_title.replace('с', 'c') formatted_title = formatted_title.replace('–', '-') return formatted_title if __name__ == '__main__': formatter = FootballOneXBetSyntaxFormatter() sport = Sport.from_dict(one_x_bet.sport) formatted_sport = formatter.apply_unified_syntax_formatting(sport) print(formatted_sport) my_path = os.path.abspath(os.path.dirname(__file__)) path = my_path + '\\sample_data\\one_x_bet.py' with open(path, 'w', encoding='utf-8') as f: print('sport =', formatted_sport, file=f)
from groupers.esports.esports_fork_grouper import EsportsForkGrouper class DotaForkGrouper(EsportsForkGrouper): _grouped_by = { r'(^\d-(st|nd|rd|th) map: )?(total (kills|roshans)|duration) (over|under) (\d+(\.\d)?)$': (3, 5), r'(^\d-(st|nd|rd|th) map: )?(total kills) (even|odd)$': (3, ), r'(^\d-(st|nd|rd|th) map: )(megacreeps) (yes|no)$': (3, ), r'(^\d-(st|nd|rd|th) map: ).+? (will first (kill roshan|lose barracks|destroy tower))$': (3, ), r'(^\d-(st|nd|rd|th) map: ).+? (first blood|will make kill \d+)$': (3, ), r'(^\d-(st|nd|rd|th) map: ).+? (will first make \d+ kills)$': (3, ), } def _get_grouped_by(self) -> dict: result = dict(DotaForkGrouper._grouped_by) result.update(EsportsForkGrouper._get_grouped_by(self)) return result def _get_handicap_targets(self): return EsportsForkGrouper._get_handicap_targets(self) + ['kills'] if __name__ == '__main__': grouper = DotaForkGrouper() dota = Sport.from_dict(marathon_dota_dict) grouped_dota = grouper.group_bets(dota) print(grouped_dota)
bets = self._update(bets, self._move_teams_left) return bets def _fix_total_rounds_and_maps(self): # Если захочешь, перепишешь по-другому, мне было проще так, вдруг мы потом решим опять менять вид total maps formatted_title = self.bet_title.lower() match = re.search('^total — (even|odd)', formatted_title) if match: formatted_title = formatted_title.replace('total —', 'total maps') match = re.search('^total (over|under)', formatted_title) if match: formatted_title = formatted_title.replace('total', 'total maps') match1 = re.search(r'map: .+? total', formatted_title) match2 = re.search(r'map: total', formatted_title) # не знаю как это в одно запихнуть ))))00)) if match1 or match2: formatted_title = formatted_title.replace('total', 'total rounds') return formatted_title if __name__ == '__main__': formatter = CSGOParimatchSyntaxFormatter() sport = Sport.from_dict(parimatch.sport) formatted_sport = formatter.apply_unified_syntax_formatting(sport) print(formatted_sport) my_path = os.path.abspath(os.path.dirname(__file__)) path = my_path + '\\sample_data\\parimatch.py' with open(path, 'w', encoding='utf-8') as f: print('sport =', formatted_sport, file=f)
class FootballForkGrouper(ForkGrouper, ABC): _grouped_by = { r'^(\d-(st|nd|rd|th) half )?.+? will (win)$': (3, ), r'^(\d-(st|nd|rd|th) half )?(draw) will (win|lose)$': (3, ), r'^(\d-(st|nd|rd|th) half )?((.+? )?(asian )?total (goals|yellow cards|corners)) (over|under) (\d+(\.\d{1,' r'2})?)$': (3, 8), r'^(\d-(st|nd|rd|th) half )?(total goals|) (even|odd)$': (3, ), r'^(\d-(st|nd|rd|th) half: )(correct score) \d+-\d+$': (3, ), } def _get_handicap_targets(self) -> list: return ['goals', 'corners', 'yellow cards'] def _get_handicap_pattern_prefix(self) -> str: return r'^((?P<prefix>\d-(st|nd|rd|th) half )?(?P<team_name>.+?) ' \ r'(asian )?handicap (?P<sign>\+|-|)(\d+(\.\d{1,2})?) (' def _get_grouped_by(self) -> dict: result = dict(FootballForkGrouper._grouped_by) result.update(ForkGrouper._get_grouped_by(self)) return result if __name__ == '__main__': grouper = FootballForkGrouper() football = Sport.from_dict(ggbet_football_dict) for match in football: grouper.group_bets(match) print(football)