middleschool / pages /1_Check_Card_List.py
Alejandro Cremades
Show Scryfall links for legal cards found when checking a card list
df9758b
raw
history blame
1.78 kB
import streamlit as st
import pandas as pd
import streamlit_common.footer
import streamlit_common.lib as lib
mslist_path = "output/middleschool.csv"
st.set_page_config(
page_title="Middle School | Check Card List",
page_icon="πŸƒ",
layout="wide",
)
st.write(
"""
# Middle School List Check
Paste or type your list here to confirm that every card in it is Middle School legal.
"""
)
mslist_df = pd.read_csv(mslist_path)
mslist_df.fillna("", inplace=True)
col1, col2 = st.columns(2)
input_list = col1.text_area(
label="##### Card list", placeholder="4 Lightning Bolt\n4 γƒœγƒΌγƒ«γƒ»γƒ©γ‚€γƒˆγƒ‹γƒ³γ‚°", height=400
)
cardnames = []
for line in input_list.split("\n"):
cardname = lib.remove_number_of_copies(line)
if cardname is not None:
cardnames.append(lib.remove_number_of_copies(cardname))
input_cards = pd.DataFrame(cardnames, columns=["cardname"])
input_cards["legalnames"] = input_cards["cardname"].apply(
lib.get_legal_cardnames, args=[mslist_df]
)
input_cards = input_cards.apply(lib.split_names_list, axis=1)
input_cards = input_cards.apply(lib.legal_to_checkmark, axis=1)
if input_cards.shape[0] > 0:
input_cards = input_cards.sort_values(by="Legal", ascending=False)
illegal_cards = 0
if input_cards.shape[0] > 0:
illegal_cards = input_cards[input_cards["Legal"] != "βœ…"].shape[0]
col2.write(f"##### This list has {illegal_cards} illegal cards")
if "English" in input_cards and "ζ—₯本θͺž" in input_cards:
col2.dataframe(
input_cards[["Legal", "English", "ζ—₯本θͺž"]],
use_container_width=True,
hide_index=True,
)
if input_cards.shape[0] > 0:
input_cards[input_cards["Legal"] == "βœ…"].apply(lib.row_to_button_link, axis=1)
streamlit_common.footer.write_footer()