def league_run_api(person): decks = league.active_decks_by(person) if len(decks) == 0: return return_json(None) run = guarantee_at_most_one_or_retire(decks) decks = league.active_decks() already_played = [m.opponent_deck_id for m in match.get_matches(run)] run.can_play = [d.person for d in decks if d.person != person and d.id not in already_played] return return_json(run)
def report(form: ReportForm) -> bool: try: db().get_lock('deck_id:{id}'.format(id=form.entry)) db().get_lock('deck_id:{id}'.format(id=form.opponent)) for m in match.get_matches(form): if int(form.opponent) == m.opponent_deck_id: form.errors[ 'result'] = 'This match was reported as You {game_wins}–{game_losses} {opponent} {date}'.format( game_wins=m.game_wins, game_losses=m.game_losses, opponent=m.opponent, date=dtutil.display_date(m.date)) return False counts = deck.count_matches(form.entry, form.opponent) if counts[int(form.entry)] >= 5: form.errors['entry'] = 'You already have 5 matches reported' return False if counts[int(form.opponent)] >= 5: form.errors[ 'opponent'] = 'Your opponent already has 5 matches reported' return False pdbot = form.get('api_token', None) == configuration.get('pdbot_api_token') if pdbot: mtgo_match_id = form.get('matchID', None) else: mtgo_match_id = None entry_name = deck.load_deck(int(form.entry)).person opp_name = deck.load_deck(int(form.opponent)).person fetcher.post_discord_webhook( configuration.get_str('league_webhook_id'), configuration.get_str('league_webhook_token'), '{entry} reported {f.entry_games}-{f.opponent_games} vs {opponent}' .format(f=form, entry=entry_name, opponent=opp_name)) db().begin() match.insert_match(dtutil.now(), form.entry, form.entry_games, form.opponent, form.opponent_games, None, None, mtgo_match_id) db().commit() return True except LockNotAcquiredException: form.errors[ 'entry'] = 'Cannot report right now, somebody else is reporting a match for you or your opponent. Try again a bit later' return False finally: db().release_lock('deck_id:{id}'.format(id=form.opponent)) db().release_lock('deck_id:{id}'.format(id=form.entry))
def add_decks(dt: datetime.datetime, competition_id: int, final: Dict[str, int], s: str) -> int: # The HTML of this page is so badly malformed that BeautifulSoup cannot really help us with this bit. rows = re.findall('<tr style=">(.*?)</tr>', s, re.MULTILINE | re.DOTALL) decks_added, ds = 0, [] matches: List[bs4.element.Tag] = [] for row in rows: cells = BeautifulSoup(row, 'html.parser').find_all('td') d = tournament_deck(cells, competition_id, dt, final) if d is not None: if d.get('id') is None or not match.get_matches(d): decks_added += 1 ds.append(d) matches += tournament_matches(d) add_ids(matches, ds) insert_matches_without_dupes(dt, matches) return decks_added
def __init__(self, d: deck.Deck, person_id: Optional[int] = None, discord_id: Optional[int] = None) -> None: super().__init__() self.deck = d self.prepare_deck(self.deck) self.cards = d.all_cards() if not self.deck.is_in_current_run(): deck.load_similar_decks([d]) # This is called 'decks' and not something more sane because of limitations of Mustache and our desire to use a partial for decktable. self.decks = [ sd for sd in d.similar_decks if not sd.is_in_current_run() ] else: self.decks = [] self.has_similar = len(self.decks) > 0 self.matches = match.get_matches(d, True) for m in self.matches: m.display_date = dtutil.display_date(m.date) if m.opponent: m.opponent_url = url_for('person', person_id=m.opponent) else: m.opponent = 'BYE' m.opponent_url = False if m.opponent_deck_id: m.opponent_deck_url = url_for('deck', deck_id=m.opponent_deck_id) else: m.opponent_deck_url = False if m.opponent_deck and m.opponent_deck.is_in_current_run(): m.opponent_deck_name = '(Active League Run)' elif m.opponent_deck: m.opponent_deck_name = m.opponent_deck.name else: m.opponent_deck_name = '-' if self.has_rounds(): m.display_round = display_round(m) self.deck['maindeck'].sort(key=lambda x: oracle.deck_sort(x['card'])) self.deck['sideboard'].sort(key=lambda x: oracle.deck_sort(x['card'])) self.archetypes = archetype.load_archetypes_deckless(order_by='a.name') self.edit_archetype_url = url_for('edit_archetypes') self.legal_formats = list( sorted(d.legal_formats, key=legality.order_score)) self.is_in_current_run = d.is_in_current_run() self.person_id = person_id self.discord_id = discord_id