File size: 2,608 Bytes
b787616
 
82e5d3a
d9b4271
82e5d3a
 
ea3872d
82e5d3a
 
 
ea3872d
81025f5
 
 
 
82e5d3a
b787616
81025f5
ea3872d
81025f5
ea3872d
81025f5
 
ea3872d
 
81025f5
 
 
 
 
 
 
 
ea3872d
 
 
b787616
82e5d3a
b787616
0b21467
 
 
 
 
b787616
 
50e3646
d9b4271
 
b787616
 
 
 
8ceea03
b787616
 
ea3872d
 
50e3646
 
 
 
 
8ceea03
50e3646
b787616
ea3872d
81025f5
 
 
ea3872d
81025f5
ea3872d
8ceea03
82e5d3a
 
 
 
d9b4271
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import streamlit as st
import pandas as pd
import urllib.parse
import streamlit_common.footer


def compose_scryfall_url(x: str) -> str:
    return f"https://scryfall.com/search?q=prefer%3Aoldest%20!%22{urllib.parse.quote_plus(x)}%22"


def row_to_link(x: pd.DataFrame) -> None:
    cardname = x["name"]
    if x.name_ja is not "":
        cardname = f"{cardname} / {x.name_ja}"
    st.markdown(f"- [{cardname}]({x.link})")


def is_legal(cardname: str) -> list:
    english_match = mslist_df[mslist_df["name"].str.lower() == cardname.lower()]
    cardname_en_list = None
    if english_match.shape[0] > 0:
        cardname_en_list = english_match["name"].to_list()
        cardname_ja_list = english_match["name_ja"].to_list()
    japanese_match = mslist_df[mslist_df["name_ja"] == cardname]
    if japanese_match.shape[0] > 0:
        cardname_en_list = japanese_match["name"].to_list()
        cardname_ja_list = japanese_match["name_ja"].to_list()
    if cardname_en_list is not None and len(cardname_en_list) > 0:
        return [
            cardname_en_list[0] or None,
            cardname_ja_list[0] or None,
        ]

    return None


mslist_path = "output/middleschool.csv"
number_shown_results = 20

st.set_page_config(
    page_title="Middle School | Card Search",
    page_icon="🃏",
    layout="wide",
)
st.write(
    """
    # Middle School Card Search

    Enter any English or Japanese text to find all Middle School legal card titles which include it.
    """
)

mslist_df = pd.read_csv(mslist_path)
mslist_df.fillna("", inplace=True)
st.write(mslist_df.shape[0], "cards are legal")

name_input = st.text_input(f"Search by card name").strip()
exact_match = is_legal(name_input)
results_en_df = mslist_df[
    mslist_df["name"].str.contains(name_input.lower(), case=False)
]
results_ja_df = mslist_df[
    mslist_df["name_ja"].str.contains(name_input.lower(), case=False)
]
results_df = results_en_df.merge(results_ja_df, how="outer")
if name_input:
    if exact_match is not None:
        cardname = exact_match[0]
        if exact_match[1] is not None:
            cardname = f"{cardname} / {exact_match[1]}"
        st.write(
            f"✅ [{cardname}]({compose_scryfall_url(exact_match[0])}) is an exact match"
        )
    st.write(results_df.shape[0], f'cards found by "{name_input}"')
    if results_df.shape[0] > number_shown_results:
        st.write(f"Top {number_shown_results} results:")
    results_df["link"] = results_df["name"].apply(compose_scryfall_url)
    results_df[:number_shown_results].transpose().apply(row_to_link)

streamlit_common.footer.write_footer()