async def generate_banner(names: List[str], background: str, v_crop: int = 33) -> str: cards = [oracle.load_card(name) for name in names] out_filepath = determine_filepath(cards, f'banner-{background}{v_crop}-') if fetch_tools.acceptable_file(out_filepath): return out_filepath canvas = Image.new('RGB', (1920, 210)) c = oracle.load_card(background) file_path = await download_scryfall_art_crop(c) if file_path: with Image.open(file_path) as img: h = v_crop / 100 * 1315 canvas.paste(img.resize((1920, 1315), Image.BICUBIC).crop((0, h, 1920, h + 210))) n = math.ceil(len(cards) / 2) x = 800 for c in cards[:n]: ip = await download_scryfall_png(c) with Image.open(ip) as img: img = img.resize((160, 213), Image.LANCZOS) canvas.paste(img, (x, 30)) x = x + img.width + 10 x = 900 for c in cards[n:]: ip = await download_scryfall_png(c) with Image.open(ip) as img: img = img.resize((160, 213), Image.LANCZOS) canvas.paste(img, (x, 60)) x = x + img.width + 10 canvas.save(out_filepath) return out_filepath
def test_info_emoji() -> None: legal_cards = oracle.legal_cards() assert len(legal_cards) > 0 legal_card = oracle.load_card('island') assert emoji.info_emoji(legal_card, no_rotation_hype=True) == ':white_check_mark:' illegal_card = oracle.load_card('black lotus') assert emoji.info_emoji(illegal_card, no_rotation_hype=True) == ':no_entry_sign:' assert emoji.info_emoji(illegal_card, verbose=True, no_rotation_hype=True) == ':no_entry_sign: (not legal in PD)'
def test_accents() -> None: c = oracle.load_card('Lim-Dûl the Necromancer') assert c is not None c = oracle.load_card('Séance') assert c is not None c = oracle.load_card('Lim-Dul the Necromancer') assert c is not None c = oracle.load_card('Seance') assert c is not None
def test_legality_emoji() -> None: legal_cards = oracle.legal_cards() assert len(legal_cards) > 0 legal_card = oracle.load_card('island') assert emoji.legal_emoji(legal_card) == ':white_check_mark:' illegal_card = oracle.load_card('black lotus') assert emoji.legal_emoji(illegal_card) == ':no_entry_sign:' assert emoji.legal_emoji(illegal_card, True) == ':no_entry_sign: (not legal in PD)'
def test_legal_formats(): swamp = oracle.load_card('Swamp') think_twice = oracle.load_card('Think Twice') fork = oracle.load_card('Fork') d = deck.Deck({'id': 0}) d.maindeck = [{'n': 59, 'card': swamp}] d.sideboard = [] assert len(d.all_cards()) == 59 formats = legality.legal_formats(d) assert len(formats) == 0 d.maindeck = [{'n': 60, 'card': swamp}] formats = legality.legal_formats(d) assert 'Penny Dreadful' in formats assert 'Legacy' in formats assert 'Penny Dreadful EMN' in formats formats = legality.legal_formats(d, {'Penny Dreadful'}) assert len(formats) == 1 assert 'Penny Dreadful' in formats assert 'Legacy' not in formats d.maindeck = [{'n': 55, 'card': swamp}, {'n': 5, 'card': think_twice}] formats = legality.legal_formats(d) assert len(d.all_cards()) == 60 assert len(legality.legal_formats(d)) == 0 d.maindeck = [{'n': 56, 'card': swamp}, {'n': 4, 'card': think_twice}] formats = legality.legal_formats(d) assert 'Legacy' in formats assert 'Modern' in formats d.sideboard = [{'n': 15, 'card': swamp}, {'n': 1, 'card': think_twice}] formats = legality.legal_formats(d) assert len(legality.legal_formats(d)) == 0 d.maindeck = [{'n': 56, 'card': swamp}, {'n': 4, 'card': fork}] d.sideboard = [{'n': 15, 'card': swamp}] formats = legality.legal_formats(d) assert 'Legacy' in formats assert 'Modern' not in formats d.maindeck = [{'n': 60, 'card': swamp}] d.sideboard = [{'n': 15, 'card': swamp}] formats = legality.legal_formats(d) assert 'Standard' in formats assert 'Modern' in formats assert 'Legacy' in formats assert 'Vintage' in formats assert 'Penny Dreadful' in formats assert 'Penny Dreadful EMN' in formats
def test_legality() -> None: card = oracle.load_card('Swamp') assert card is not None assert card.legalities['Standard'] == 'Legal' assert card.legalities['Modern'] == 'Legal' assert card.legalities['Legacy'] == 'Legal' assert card.legalities['Vintage'] == 'Legal' assert card.legalities['Penny Dreadful'] == 'Legal' card = oracle.load_card('Black Lotus') assert card is not None assert 'Standard' not in card.legalities.keys() assert 'Modern' not in card.legalities.keys() assert card.legalities['Legacy'] == 'Banned' assert card.legalities['Vintage'] == 'Restricted' assert 'Penny Dreadful' not in card.legalities.keys()
def test_imagedownload() -> None: filepath = '{dir}/{filename}'.format(dir=configuration.get('image_dir'), filename='island.jpg') if fetcher_internal.acceptable_file(filepath): os.remove(filepath) c = [oracle.load_card('Island')] assert image_fetcher.download_image(c) is not None
def test_fallbackimagedownload() -> None: filepath = '{dir}/{filename}'.format(dir=configuration.get('image_dir'), filename='nalathni-dragon.jpg') if fetch_tools.acceptable_file(filepath): os.remove(filepath) c = [oracle.load_card('Nalathni Dragon')] assert image_fetcher.download_image(c) is not None
def cards_from_names_with_mode( cards: Sequence[Optional[str]], mode: str, preferred_printing: Optional[str] = None) -> List[Card]: return [ copy_with_mode(oracle.load_card(c), mode, preferred_printing) for c in cards if c is not None ]
def init() -> None: if FORMATS: return print('Updating Legalities…') assert len(oracle.legal_cards()) > 0 all_known = oracle.load_card('island').legalities # assert 'Penny Dreadful EMN' in all_known assert 'Penny Dreadful' in all_known assert 'Vintage' in all_known FORMATS.clear() for v in db().values('SELECT name FROM format'): FORMATS.add(v)
def init(): if FORMATS: return print('Updating Legalities...') assert len(oracle.legal_cards()) > 0 all_known = oracle.load_card('island').legalities for s in SEASONS: if s == rotation.last_rotation_ex()['code']: break if not 'Penny Dreadful {s}'.format(s=s) in all_known: multiverse.set_legal_cards(season=s) FORMATS.clear() for v in db().values('SELECT name FROM format'): FORMATS.add(v)
def test_cmc() -> None: card = oracle.load_card('Odds // Ends') assert card.cmc == 7 card = oracle.load_card('Ancestral Vision') assert card.cmc == 0 card = oracle.load_card('Delver of Secrets') assert card.cmc == 1 card = oracle.load_card('Gisela, the Broken Blade') assert card.cmc == 4 card = oracle.load_card('Budoka Gardener') assert card.cmc == 2 card = oracle.load_card('Driven // Despair') assert card.cmc == 4
def card_api(card): return return_json(oracle.load_card(card))
def test_aether() -> None: c = oracle.load_card('aether Spellbomb') assert c is not None
def card_api(card: str) -> Response: return return_json(oracle.load_card(card))