def flavor_text(c: Card) -> str: for printing in oracle.get_printings(c): if c.preferred_printing is not None and c.preferred_printing != printing.set_code: continue if printing.flavor is not None: return '\n' + printing.flavor + '\n-**' + oracle.get_set( printing.set_id).name + '**' return 'No flavor text available'
def download_image(cards) -> str: # helper functions: imagename = basename(cards) # Hash the filename if it's otherwise going to be too large to use. if len(imagename) > 240: imagename = hashlib.md5(imagename.encode('utf-8')).hexdigest() filename = imagename + '.jpg' filepath = '{dir}/{filename}'.format(dir=configuration.get('image_dir'), filename=filename) if internal.acceptable_file(filepath): return filepath 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)) if internal.acceptable_file(filepath): return filepath print('Trying to get scryfall image for {card}'.format(card=cards[0])) try: internal.store(scryfall_image(cards[0]), filepath) except FetchException as e: print('Error: {e}'.format(e=e)) if internal.acceptable_file(filepath): return filepath printings = oracle.get_printings(cards[0]) for p in printings: print("Trying to get MCI image for {imagename}".format( imagename=imagename)) try: internal.store(mci_image(p), filepath) if internal.acceptable_file(filepath): return filepath except FetchException as e: print('Error: {e}'.format(e=e)) print('Trying to get fallback image for {imagename}'.format( imagename=imagename)) try: internal.store(gatherer_image(p), filepath) if internal.acceptable_file(filepath): return filepath except FetchException as e: print('Error: {e}'.format(e=e)) return None
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