def single_card_text_internal(client: Client, requested_card: Card, disable_emoji: bool) -> str: mana = emoji.replace_emoji(''.join(requested_card.mana_cost or []), client) legal = ' — ' + emoji.legal_emoji(requested_card, True) if disable_emoji: legal = '' if requested_card.get('mode', None) == '$': text = '{name} {legal} — {price}'.format( name=requested_card.name, price=fetcher.card_price_string(requested_card), legal=legal) else: text = '{name} {mana} — {type}{legal}'.format(name=requested_card.name, mana=mana, type=requested_card.type, legal=legal) if requested_card.bugs: for bug in requested_card.bugs: text += '\n:beetle:{rank} bug: {bug}'.format( bug=bug['description'], rank=bug['classification']) if bug['last_confirmed'] < (dtutil.now() - datetime.timedelta(days=60)): time_since_confirmed = (dtutil.now() - bug['last_confirmed']).seconds text += ' (Last confirmed {time} ago.)'.format( time=dtutil.display_time(time_since_confirmed, 1)) return text
def deck_sort(c: Card) -> str: s = '' if c.is_creature(): s += 'A' elif c.is_land(): s += 'C' else: s += 'B' m = 'A' for cost in c.get('mana_cost') or (): if mana.has_x(cost): m = 'X' s += m s += str(c.cmc).zfill(10) s += c.name return s
def load_cards(names: Collection[str] = None, where: Optional[str] = None) -> List[Card]: if names: setnames = set(names) else: setnames = set() if setnames: names_clause = 'LOWER(c.name) IN ({names})'.format(names=', '.join( sqlescape(name).lower() for name in setnames)) else: names_clause = '(1 = 1)' if where is None: where = '(1 = 1)' sql = multiverse.cached_base_query('({where} AND {names})'.format( where=where, names=names_clause)) rs = db().execute(sql) if setnames and len(setnames) != len(rs): missing = setnames.symmetric_difference([r['name'] for r in rs]) raise TooFewItemsException( 'Expected `{namelen}` and got `{rslen}` with `{names}`. missing=`{missing}`' .format(namelen=len(setnames), rslen=len(rs), names=setnames, missing=missing)) return [Card(r) for r in rs]
def if_todays_prices(out=True): current_format = multiverse.get_format_id('Penny Dreadful') if out: not_clause = '' compare = '<' else: not_clause = 'NOT' compare = '>=' where = """ c.id {not_clause} IN (SELECT card_id FROM card_legality WHERE format_id = {format}) AND c.name in (SELECT name from prices.cache where week {compare} 0.5) AND c.layout IN ({layouts}) """.format(not_clause=not_clause, format=current_format, compare=compare, layouts=', '.join([ sqlescape(k) for k, v in multiverse.layouts().items() if v ])) rs = db().execute(multiverse.cached_base_query(where=where)) out = [Card(r) for r in rs] return sorted(out, key=lambda card: card['name'])
def test_noimageavailable() -> None: c = Card({ 'name': "Barry's Land", 'id': 0, 'multiverseid': 0, 'names': "Barry's Land" }) assert image_fetcher.download_image([c]) is None
def query_diff_formats(f1, f2): where = """ c.id IN (SELECT card_id FROM card_legality WHERE format_id = {format1}) AND c.id NOT IN (SELECT card_id FROM card_legality WHERE format_id = {format2}) """.format(format1=f1, format2=f2) rs = db().select(multiverse.cached_base_query(where=where)) out = [Card(r) for r in rs] return sorted(out, key=lambda card: card['name'])
def bugged_cards() -> List[Card]: sql = multiverse.cached_base_query('bugs IS NOT NULL') rs = db().select(sql) return [Card(r) for r in rs]
def prepare_card(self, c: Card) -> None: c.url = '/cards/{id}/'.format(id=c.name) c.img_url = url_for('image', c=c.name) c.card_img_class = 'two-faces' if c.layout in ['double-faced', 'meld'] else '' c.pd_legal = c.legalities.get('Penny Dreadful', False) and c.legalities['Penny Dreadful'] != 'Banned' c.legal_formats = {k for k, v in c.legalities.items() if v != 'Banned'} c.has_legal_format = len(c.legal_formats) > 0 if c.get('all_num_decks') is not None: c.all_show_record = c.get('all_wins') or c.get('all_losses') or c.get('all_draws') c.has_decks = len(c.get('decks', [])) > 0 counter = Counter() # type: ignore for d in c.get('decks', []): for c2 in d.maindeck: if not c2.card.type.startswith('Basic Land') and not c2['name'] == c.name: counter[c2['name']] += c2['n'] most_common_cards = counter.most_common(NUM_MOST_COMMON_CARDS_TO_LIST) c.most_common_cards = [] cs = oracle.cards_by_name() for v in most_common_cards: self.prepare_card(cs[v[0]]) c.most_common_cards.append(cs[v[0]]) c.has_most_common_cards = len(c.most_common_cards) > 0
def get_all_cards() -> List[Card]: rs = db().execute(cached_base_query()) return [Card(r) for r in rs]