Esempio n. 1
0
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)
    mana = mana.replace('|', ' // ')
    legal = ' — ' + emoji.info_emoji(requested_card, verbose=True)
    if disable_emoji:
        legal = ''
    if requested_card.get('mode', None) == '$':
        text = '{name} {legal} — {price}'.format(
            name=requested_card.name,
            price=card_price.card_price_string(requested_card),
            legal=legal)
    else:
        text = '{name} {mana} — {type}{legal}'.format(
            name=requested_card.name,
            mana=mana,
            type=requested_card.type_line,
            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']).total_seconds()
                text += ' (Last confirmed {time} ago.)'.format(
                    time=dtutil.display_time(time_since_confirmed, 1))
    return text
Esempio n. 2
0
    def prepare_card(self, c: Card) -> None:
        try:
            tournament_only = self.tournament_only #type: ignore
            # mypy complains we haven't declared tournament_only, but that's fine since we're
            # catching the error if it isn't defined by a subclass
        except AttributeError:
            tournament_only = False

        if tournament_only:
            c.url = url_for('.card_tournament', name=c.name)
        else:
            c.url = url_for('.card', name=c.name)

        c.img_url = url_for('image', c=c.name)
        c.card_img_class = 'two-faces' if c.layout in ['transform', '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('num_decks') is not None:
            c.show_record = c.get('wins') or c.get('losses') or c.get('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_line.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
Esempio n. 3
0
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 scryfall_image(c: Card, version: str = '', face: str = None) -> str:
    if face == 'meld':
        name = c.names[1]
    elif ' // ' in c.name:
        name = c.name.replace(' // ', '/')
    else:
        name = c.name
    p = oracle.get_printing(c, c.get('preferred_printing'))
    if p is not None:
        u = f'https://api.scryfall.com/cards/{p.set_code}/{p.number}?format=image'
    else:
        u = 'https://api.scryfall.com/cards/named?exact={c}&format=image'.format(c=escape(name))
    if version:
        u += '&version={v}'.format(v=escape(version))
    if face and face != 'meld':
        u += '&face={f}'.format(f=escape(face))
    return u
Esempio n. 5
0
    def prepare_card(self, c: Card) -> None:
        self.prepare_card_urls(c)
        c.card_img_class = 'two-faces' if c.layout in ['transform', '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.non_pd_legal_formats = {
            k
            for k, v in c.legalities.items()
            if 'Penny Dreadful' not in k and v != 'Banned'
        }
        c.has_legal_format = len(c.legal_formats) > 0
        prepare.set_legal_icons(c)
        if c.get('num_decks') is not None:
            c.show_record = c.get('wins') or c.get('losses') or c.get('draws')

        c.has_decks = len(c.get('decks', [])) > 0
        if not c.has_decks:
            c.has_most_common_cards = False
            return

        counter = Counter()  # type: ignore
        for d in c.get('decks', []):
            for c2 in d.maindeck:
                if not c2.card.type_line.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