Exemplo 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)
    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
Exemplo n.º 2
0
 def prepare_card(self, c: Card) -> None:
     c.url = '/cards/{id}/'.format(id=c.name)
     c.img_url = 'http://magic.bluebones.net/proxies/index2.php?c={name}'.format(
         name=urllib.parse.quote(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 = set(
         [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
Exemplo 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