File size: 1,785 Bytes
b787616
 
d9b4271
14f90e3
59718b5
ea3872d
b787616
82e5d3a
59718b5
b787616
0b21467
5dbcf27
0b21467
 
 
6085806
 
 
b787616
6085806
59718b5
 
b787616
 
8ceea03
59718b5
b787616
59718b5
14f90e3
50e3646
 
 
 
 
8ceea03
50e3646
b787616
0ff4e79
 
 
 
ea3872d
59718b5
ea3872d
59718b5
82e5d3a
59718b5
14f90e3
 
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
import streamlit as st
import pandas as pd
import streamlit_common.footer
import streamlit_common.lib as lib
import streamlit_common.locale

mslist_path = "output/middleschool.csv"
number_shown_results = 20
_ = streamlit_common.locale.get_locale()

st.set_page_config(
    page_title="MTG Middle School | Card Search",
    page_icon="🃏",
    layout="wide",
)
lang = st.sidebar.radio(
    label="Language / 言語",
    options=["English", "日本語"],
)
l = "ja" if lang == "日本語" else "en"
st.write(f'# {_["search"]["title"][l]}')
st.write(_["search"]["instructions"][l])

mslist_df = pd.read_csv(mslist_path)
mslist_df.fillna("", inplace=True)
st.write(f'**{mslist_df.shape[0]}**{_["search"]["cards_are_legal"][l]}')

name_input = st.text_input(_["search"]["search_by_card_name"][l]).strip()
exact_match = lib.get_legal_cardnames(name_input, mslist_df)
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[0]:
        cardname = exact_match[1]
        if exact_match[2] is not None:
            cardname = f"{cardname} / {exact_match[2]}"
        st.write(
            f'✅ [{cardname}]({lib.compose_scryfall_url(exact_match[1])}) {_["search"]["exact_match"][l]}'
        )
    st.write(f'**{results_df.shape[0]}**{_["search"]["cards_found"][l]}')
    if results_df.shape[0] > number_shown_results:
        st.write(_["search"]["top_results"][l])
    results_df["link"] = results_df["name"].apply(lib.compose_scryfall_url)
    results_df[:number_shown_results].transpose().apply(lib.row_to_link)

streamlit_common.footer.write_footer()