How to use the scrython.cards.Named 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 NandaScott / Scrython / examples / get_and_format_card.py View on Github external
import scrython

getCard = str(input("What card would you like me to search? "))

card = scrython.cards.Named(fuzzy=getCard)

if card.object() == 'error':
    print(card.scryfallJson['details'])

if card.type_line() == 'Creature':
    PT = "({}/{})".format(card.power(), card.toughness())
else:
    PT = ""

if card.cmc() == 0:
    mana_cost = ""
else:
    mana_cost = card.mana_cost()

string = """
{cardname} {mana_cost}
github ndepaola / mtg-autoproxy / scripts / sc_scan.py View on Github external
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:
        print("Exception: " + str(e))
github NandaScott / Scrython / examples / discord_bot.py View on Github external
async def mtg(*, name):
    getCard = str(name)

    await asyncio.sleep(0.05)
    card = scrython.cards.Named(fuzzy=getCard)

    if card.type_line() == 'Creature':
        PT = "({}/{})".format(card.power(), card.toughness())
    else:
        PT = ""

    if card.cmc() == 0:
        mana_cost = ""
    else:
        mana_cost = card.mana_cost()

    string = """
{cardname} {mana_cost}
{type_line} {set_code} {rarity}
{oracle_text}{power_toughness}
    """.format(
github ndepaola / mtg-autoproxy / scripts / get_card_info.py View on Github external
elif card.layout() == "normal":
        # normal card
        card_json = get_dict(card)
        save_json(card_json)

    elif card.layout() == "meld":
        card_json = get_dict(card)
        card_json["frame_effect"] = "mooneldrazidfc"
        card_json["layout"] = "transform"
        if "meld them" in card_json["text"] or "Melds with" in card_json["text"]:
            card_json["face"] = "front"
            # get the power and toughness of the backside
            meldbackidx = [card.all_parts()[x]["component"] for x in range(0, len(card.all_parts()))].index("meld_result")
            meldbackname = card.all_parts()[meldbackidx]["name"]
            meldback = scrython.cards.Named(fuzzy=meldbackname)

            # assume meld cards flip into creatures
            power = meldback.power()
            toughness = meldback.toughness()
            card_json["back_power"] = power
            card_json["back_toughness"] = toughness
        else:
            card_json["face"] = "back"
            card_json["colourIdentity"] = card.colors()
        save_json(card_json)

    else:
        print("Unsupported")
    # TODO: Add more card types. Meld? Sagas?
github ndepaola / mtg-autoproxy / scripts / get_card_info.py View on Github external
def save_json(card_json):
    json_dump = json.dumps(card_json)
    print(card_json)
    with open(sys.path[0] + "/card.json", 'w') as f:
        json.dump(json_dump, f)


if __name__ == "__main__":

    cardname = sys.argv[1]
    print("Asking Scryfall for information for: " + cardname)
    # Use Scryfall to search for this card
    time.sleep(0.05)
    card = scrython.cards.Named(fuzzy=cardname)

    if card.layout() == "transform":
        if card.card_faces()[0]["name"] == cardname:
            # front face
            card_json = get_dict_tf(card.card_faces()[0], card)
            try:
                power = card.card_faces()[1]["power"]
                toughness = card.card_faces()[1]["toughness"]
                card_json["back_power"] = power
                card_json["back_toughness"] = toughness
            except KeyError:
                pass
            card_json["face"] = "front"
            save_json(card_json)
        elif card.card_faces()[1]["name"] == cardname:
            # back face