How to use the scrython.foundation.ScryfallError function in scrython

To help you get started, we’ve selected a few scrython examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ndepaola / mtg-autoproxy / scripts / sc_scan.py View on Github external
# Write image to disk, casting to uint8
    imageio.imwrite("../art_raw/" + cardname + " (" + card["artist"] + ").jpg", im_recon_sc.astype(np.uint8))
    print("Successfully processed scan for {}.".format(cardname))


if __name__ == "__main__":
    cardname = input("Card name (exact): ")
    try:
        # If the card specifies which set to retrieve the scan from, do that
        try:
            pipe_idx = cardname.index("|")
            query = cardname[0:pipe_idx] + " set=" + cardname[pipe_idx + 1:]
            card = scrython.cards.Search(q=query).data()[0]
            print("Processing: " + cardname[0:pipe_idx] + ", set: " + cardname[pipe_idx + 1:])
            cardname = cardname[0:pipe_idx]
        except (ValueError, scrython.foundation.ScryfallError):
            card = scrython.cards.Named(fuzzy=cardname).scryfallJson
            print("Processing: " + cardname)

        # Handle case of transform card
        if card["layout"] == "transform":
            card_idx = [card["card_faces"][x]["name"] for x in range(0, 2)].index(cardname)
            card["image_uris"] = {}
            card["image_uris"]["art_crop"] = card["card_faces"][card_idx]["image_uris"]["art_crop"]
            card["name"] = card["card_faces"][card_idx]["name"]

        # If the card is on Scryfall with that exact name:
        if card["name"] == cardname:
            process_scan(card, cardname)
        else:
            print("Couldn't find that card.")
    except Exception as e: