def download_bluebones_image(cards: List[Card], filepath: str) -> bool:
    print('Trying to get image for {cards}'.format(cards=', '.join(card.name for card in cards)))
    try:
        internal.store(bluebones_image(cards), filepath)
    except FetchException as e:
        print('Error: {e}'.format(e=e))
    return internal.acceptable_file(filepath)
def download_scryfall_image(cards: List[Card], filepath: str, version: str = '') -> bool:
    print('Trying to get scryfall image for {card}'.format(card=cards[0]))
    try:
        internal.store(scryfall_image(cards[0], version=version), filepath)
    except FetchException as e:
        print('Error: {e}'.format(e=e))
    return internal.acceptable_file(filepath)
Пример #3
0
def download_scryfall_card_image(card: Card,
                                 filepath: str,
                                 version: str = '') -> bool:
    try:
        if card.is_double_sided():
            paths = [
                re.sub('.jpg$', '.a.jpg', filepath),
                re.sub('.jpg$', '.b.jpg', filepath)
            ]
            internal.store(scryfall_image(card, version=version), paths[0])
            if card.layout == 'transform':
                internal.store(
                    scryfall_image(card, version=version, face='back'),
                    paths[1])
            if card.layout == 'meld':
                internal.store(
                    scryfall_image(card, version=version, face='meld'),
                    paths[1])
            if (internal.acceptable_file(paths[0])
                    and internal.acceptable_file(paths[1])):
                save_composite_image(paths, filepath)
        else:
            internal.store(scryfall_image(card, version=version), filepath)
    except FetchException as e:
        print('Error: {e}'.format(e=e))
    return internal.acceptable_file(filepath)
def download_mci_image(cards: List[Card], filepath: str) -> bool:
    printings = oracle.get_printings(cards[0])
    for p in printings:
        print('Trying to get MCI image for {imagename}'.format(imagename=os.path.basename(filepath)))
        try:
            internal.store(mci_image(p), filepath)
            if internal.acceptable_file(filepath):
                return True
        except FetchException as e:
            print('Error: {e}'.format(e=e))
        print('Trying to get fallback image for {imagename}'.format(imagename=os.path.basename(filepath)))
        try:
            img = gatherer_image(p)
            if img:
                internal.store(img, filepath)
            if internal.acceptable_file(filepath):
                return True
        except FetchException as e:
            print('Error: {e}'.format(e=e))
    return False