def tournament(url: str, name: str) -> int: s = fetcher.internal.fetch(url, character_encoding='utf-8', retry=True) # Tournament details soup = BeautifulSoup(s, 'html.parser') cell = soup.find('div', {'id': 'EventReport'}).find_all('td')[1] name = cell.find('a').string.strip() day_s = cell.find('br').next.strip() if '-0001' in day_s: # Tournament has been incorrectly configured. return 0 dt, competition_series = get_dt_and_series(name, day_s) top_n = find_top_n(soup) # Tournaments that currently advertise a "top 0" are unstarted/in progress and should be ignored for now. if top_n == competition.Top.NONE: return 0 db().begin('tournament') competition_id = competition.get_or_insert_competition( dt, dt, name, competition_series, url, top_n) ranks = rankings(soup) medals = medal_winners(s) final = finishes(medals, ranks) n = add_decks(dt, competition_id, final, s) db().commit('tournament') return n
def tournament(url, name): s = fetcher.internal.fetch(url, character_encoding='utf-8') # Tournament details soup = BeautifulSoup(s, 'html.parser') cell = soup.find('div', {'id': 'EventReport'}).find_all('td')[1] # Hack in the known start time because it's not in the page. start_time = '19:00' name = cell.find('a').string.strip() if 'Saturday' in name or 'Sunday' in name or 'PDS' in name: start_time = '13:30' date_s = cell.find('br').next.strip() + ' {start_time}'.format( start_time=start_time) if '-0001' in date_s: # Tournament has been incorrectly configured. return 0 dt = dtutil.parse(date_s, '%d %B %Y %H:%M', dtutil.GATHERLING_TZ) competition_id = competition.get_or_insert_competition( dt, dt, name, 'Penny Dreadful {day}s'.format( day=dtutil.day_of_week(dt, dtutil.GATHERLING_TZ)), url) table = soup.find(text='Current Standings').find_parent('table') ranks = rankings(table) return add_decks(dt, competition_id, ranks, s)
def active_league(): where = 'c.id = ({id_query})'.format(id_query=active_competition_id_query()) leagues = competition.load_competitions(where) if len(leagues) == 0: start_date = dtutil.now(tz=dtutil.WOTC_TZ) end_date = determine_end_of_league(start_date) name = determine_league_name(end_date) comp_id = competition.get_or_insert_competition(start_date, end_date, name, 'League', None) leagues = [competition.load_competition(comp_id)] return guarantee.exactly_one(leagues)
def tournament(comp: Dict[str, Any]) -> None: comp = fetch_tools.fetch_json(comp['url']) dt = dtutil.ts2dt(comp['start_date']) de = dtutil.ts2dt(comp['end_date']) competition_id = competition.get_or_insert_competition( dt, de, comp['name'], comp['series_name'], comp['url'], top.Top(comp['top_n'])) loaded_competition = competition.load_competition(competition_id) if loaded_competition.num_decks < comp['num_decks']: for d in comp['decks']: store_deck(d)
def active_league(should_load_decks: bool = False) -> competition.Competition: where = 'c.id = ({id_query})'.format(id_query=active_competition_id_query()) leagues = competition.load_competitions(where, should_load_decks=should_load_decks) if len(leagues) == 0: start_date = dtutil.now(tz=dtutil.WOTC_TZ) end_date = determine_end_of_league(start_date, seasons.next_rotation()) name = determine_league_name(start_date, end_date) comp_id = competition.get_or_insert_competition(start_date, end_date, name, 'League', None, competition.Top.EIGHT) if not comp_id: raise InvalidDataException(f'No competition id with {start_date}, {end_date}, {name}') leagues = [competition.load_competition(comp_id)] return guarantee.exactly_one(leagues)
def active_league(): where = 'c.id = ({id_query})'.format( id_query=active_competition_id_query()) leagues = competition.load_competitions(where) if len(leagues) == 0: start_date = datetime.datetime.combine( dtutil.now().date(), datetime.time(tzinfo=dtutil.WOTC_TZ)) end_date = determine_end_of_league(start_date) name = "League {MM} {YYYY}".format( MM=calendar.month_name[end_date.month], YYYY=end_date.year) comp_id = competition.get_or_insert_competition( start_date, end_date, name, 'League', None) leagues = [competition.load_competition(comp_id)] return guarantee.exactly_one(leagues)
def insert_competition(name: str, date: datetime.datetime, event: Event) -> int: if not name or not event.start or event.finalrounds is None or not event.series: raise InvalidDataException( f'Unable to insert Gatherling tournament `{name}` with `{event}`') url = gatherling_url('/eventreport.php?event=' + urllib.parse.quote(name)) if event.finalrounds == 0: top_n = top.Top.NONE else: try: top_n = top.Top(pow(2, event.finalrounds)) except ValueError as e: raise InvalidDataException( f'Unexpected number of finalrounds: `{event.finalrounds}`' ) from e return competition.get_or_insert_competition(date, date, name, event.series, url, top_n)
def tournament(url: str, name: str) -> int: s = fetcher.internal.fetch(url, character_encoding='utf-8') # Tournament details soup = BeautifulSoup(s, 'html.parser') cell = soup.find('div', {'id': 'EventReport'}).find_all('td')[1] name = cell.find('a').string.strip() day_s = cell.find('br').next.strip() if '-0001' in day_s: # Tournament has been incorrectly configured. return 0 dt, competition_series = get_dt_and_series(name, day_s) top_n = find_top_n(soup) competition_id = competition.get_or_insert_competition(dt, dt, name, competition_series, url, top_n) ranks = rankings(soup) medals = medal_winners(s) final = finishes(medals, ranks) return add_decks(dt, competition_id, final, s)