Spaces:
Running
Running
Merge pull request #87 from alecrem/feature/issue-86/show-banned-cards
Browse files- Middle_School_Card_Search.py +26 -6
- pages/1_Check_Card_List.py +20 -4
- streamlit_common/lib.py +10 -21
- streamlit_common/locale.py +20 -2
Middle_School_Card_Search.py
CHANGED
@@ -4,9 +4,22 @@ import streamlit_common.footer
|
|
4 |
import streamlit_common.lib as lib
|
5 |
import streamlit_common.locale
|
6 |
|
7 |
-
mslist_path = "static/
|
8 |
_ = streamlit_common.locale.get_locale()
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
if "number_shown_results" not in st.session_state:
|
11 |
st.session_state["number_shown_results"] = 20
|
12 |
if "lang" not in st.session_state:
|
@@ -41,7 +54,9 @@ st.write(_["search"]["instructions"][l])
|
|
41 |
|
42 |
mslist_df = pd.read_csv(mslist_path)
|
43 |
mslist_df.fillna("", inplace=True)
|
44 |
-
st.write(
|
|
|
|
|
45 |
|
46 |
results_df = mslist_df
|
47 |
|
@@ -155,16 +170,21 @@ if results_df.shape[0] < mslist_df.shape[0]:
|
|
155 |
cardname = exact_match[1]
|
156 |
if exact_match[2] is not None:
|
157 |
cardname = f"{cardname} / {exact_match[2]}"
|
158 |
-
|
159 |
-
|
160 |
-
|
|
|
|
|
|
|
|
|
|
|
161 |
st.write(f'**{results_df.shape[0]}**{_["search"]["cards_found"][l]}')
|
162 |
if results_df.shape[0] > st.session_state["number_shown_results"]:
|
163 |
st.write(_["search"]["top_results"][l])
|
164 |
|
165 |
results_df["link"] = results_df["name"].apply(lib.compose_scryfall_url)
|
166 |
results_df[: st.session_state["number_shown_results"]].transpose().apply(
|
167 |
-
|
168 |
)
|
169 |
|
170 |
if results_df.shape[0] > st.session_state["number_shown_results"]:
|
|
|
4 |
import streamlit_common.lib as lib
|
5 |
import streamlit_common.locale
|
6 |
|
7 |
+
mslist_path = "static/middleschool_extra_fields_with_banned.csv"
|
8 |
_ = streamlit_common.locale.get_locale()
|
9 |
|
10 |
+
|
11 |
+
def row_to_link(row: pd.DataFrame) -> None:
|
12 |
+
"""Prints a list item with a Scryfall link for the card in the row passed"""
|
13 |
+
cardname = row["name"]
|
14 |
+
if row.name_ja is not "":
|
15 |
+
cardname = f"{cardname} / {row.name_ja}"
|
16 |
+
link = f"[{cardname}]({row.link})"
|
17 |
+
if row.banned:
|
18 |
+
link = f"🈲 {link} ({_['legality']['banned'][l]})"
|
19 |
+
link = f"- {link}"
|
20 |
+
st.write(link)
|
21 |
+
|
22 |
+
|
23 |
if "number_shown_results" not in st.session_state:
|
24 |
st.session_state["number_shown_results"] = 20
|
25 |
if "lang" not in st.session_state:
|
|
|
54 |
|
55 |
mslist_df = pd.read_csv(mslist_path)
|
56 |
mslist_df.fillna("", inplace=True)
|
57 |
+
st.write(
|
58 |
+
f'**{mslist_df[mslist_df["banned"]==False].shape[0]}**{_["search"]["cards_are_legal"][l]}'
|
59 |
+
)
|
60 |
|
61 |
results_df = mslist_df
|
62 |
|
|
|
170 |
cardname = exact_match[1]
|
171 |
if exact_match[2] is not None:
|
172 |
cardname = f"{cardname} / {exact_match[2]}"
|
173 |
+
if exact_match[3]:
|
174 |
+
st.write(
|
175 |
+
f'🈲 [{cardname}]({lib.compose_scryfall_url(exact_match[1])}) {_["search"]["banned_match"][l]}'
|
176 |
+
)
|
177 |
+
else:
|
178 |
+
st.write(
|
179 |
+
f'✅ [{cardname}]({lib.compose_scryfall_url(exact_match[1])}) {_["search"]["exact_match"][l]}'
|
180 |
+
)
|
181 |
st.write(f'**{results_df.shape[0]}**{_["search"]["cards_found"][l]}')
|
182 |
if results_df.shape[0] > st.session_state["number_shown_results"]:
|
183 |
st.write(_["search"]["top_results"][l])
|
184 |
|
185 |
results_df["link"] = results_df["name"].apply(lib.compose_scryfall_url)
|
186 |
results_df[: st.session_state["number_shown_results"]].transpose().apply(
|
187 |
+
row_to_link
|
188 |
)
|
189 |
|
190 |
if results_df.shape[0] > st.session_state["number_shown_results"]:
|
pages/1_Check_Card_List.py
CHANGED
@@ -4,9 +4,21 @@ import streamlit_common.footer
|
|
4 |
import streamlit_common.lib as lib
|
5 |
import streamlit_common.locale
|
6 |
|
7 |
-
mslist_path = "static/
|
8 |
_ = streamlit_common.locale.get_locale()
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
if "lang" not in st.session_state:
|
11 |
st.session_state["lang"] = "en"
|
12 |
|
@@ -51,13 +63,15 @@ input_cards["legalnames"] = input_cards["cardname"].apply(
|
|
51 |
lib.get_legal_cardnames, args=[mslist_df]
|
52 |
)
|
53 |
input_cards = input_cards.apply(lib.split_names_list, axis=1)
|
54 |
-
input_cards = input_cards.apply(
|
55 |
if input_cards.shape[0] > 0:
|
56 |
input_cards = input_cards.sort_values(by="Legal", ascending=False)
|
57 |
|
58 |
illegal_cards = 0
|
59 |
if input_cards.shape[0] > 0:
|
60 |
-
illegal_cards = input_cards[
|
|
|
|
|
61 |
|
62 |
col2.write(
|
63 |
f'##### {_["check"]["illegal_cards_1"][l]}{illegal_cards}{_["check"]["illegal_cards_2"][l]}'
|
@@ -70,6 +84,8 @@ if "English" in input_cards and "日本語" in input_cards:
|
|
70 |
)
|
71 |
|
72 |
if input_cards.shape[0] > 0:
|
73 |
-
input_cards[input_cards["Legal"] == "✅"].apply(
|
|
|
|
|
74 |
|
75 |
streamlit_common.footer.write_footer()
|
|
|
4 |
import streamlit_common.lib as lib
|
5 |
import streamlit_common.locale
|
6 |
|
7 |
+
mslist_path = "static/middleschool_with_banned.csv"
|
8 |
_ = streamlit_common.locale.get_locale()
|
9 |
|
10 |
+
|
11 |
+
def legal_to_checkmark(row: pd.DataFrame) -> pd.DataFrame:
|
12 |
+
if row["isbanned"]:
|
13 |
+
row["Legal"] = f"🈲 {_['legality']['banned'][l]}"
|
14 |
+
return row
|
15 |
+
if row["islegal"]:
|
16 |
+
row["Legal"] = f"✅ {_['legality']['legal'][l]}"
|
17 |
+
return row
|
18 |
+
row["Legal"] = f"🚫 {_['legality']['not_legal'][l]}"
|
19 |
+
return row
|
20 |
+
|
21 |
+
|
22 |
if "lang" not in st.session_state:
|
23 |
st.session_state["lang"] = "en"
|
24 |
|
|
|
63 |
lib.get_legal_cardnames, args=[mslist_df]
|
64 |
)
|
65 |
input_cards = input_cards.apply(lib.split_names_list, axis=1)
|
66 |
+
input_cards = input_cards.apply(legal_to_checkmark, axis=1)
|
67 |
if input_cards.shape[0] > 0:
|
68 |
input_cards = input_cards.sort_values(by="Legal", ascending=False)
|
69 |
|
70 |
illegal_cards = 0
|
71 |
if input_cards.shape[0] > 0:
|
72 |
+
illegal_cards = input_cards[
|
73 |
+
input_cards["Legal"] != f"✅ {_['legality']['legal'][l]}"
|
74 |
+
].shape[0]
|
75 |
|
76 |
col2.write(
|
77 |
f'##### {_["check"]["illegal_cards_1"][l]}{illegal_cards}{_["check"]["illegal_cards_2"][l]}'
|
|
|
84 |
)
|
85 |
|
86 |
if input_cards.shape[0] > 0:
|
87 |
+
input_cards[input_cards["Legal"] == f"✅ {_['legality']['legal'][l]}"].apply(
|
88 |
+
lib.row_to_button_link, axis=1
|
89 |
+
)
|
90 |
|
91 |
streamlit_common.footer.write_footer()
|
streamlit_common/lib.py
CHANGED
@@ -9,14 +9,6 @@ def compose_scryfall_url(cardname: str) -> str:
|
|
9 |
return f"https://scryfall.com/search?q=prefer%3Aoldest%20!%22{urllib.parse.quote_plus(cardname)}%22"
|
10 |
|
11 |
|
12 |
-
def row_to_link(row: pd.DataFrame) -> None:
|
13 |
-
"""Prints a list item with a Scryfall link for the card in the row passed"""
|
14 |
-
cardname = row["name"]
|
15 |
-
if row.name_ja is not "":
|
16 |
-
cardname = f"{cardname} / {row.name_ja}"
|
17 |
-
st.write(f"- [{cardname}]({row.link})")
|
18 |
-
|
19 |
-
|
20 |
def row_to_button_link(row: pd.DataFrame) -> None:
|
21 |
"""Prints a list item with a Scryfall link for the card in the row passed"""
|
22 |
cardname = row.English
|
@@ -33,17 +25,21 @@ def get_legal_cardnames(cardname: str, mslist_df: pd.DataFrame) -> list:
|
|
33 |
return [False, [], []]
|
34 |
cardname_en_list = []
|
35 |
cardname_ja_list = []
|
|
|
36 |
legal = False
|
|
|
37 |
english_match = mslist_df[mslist_df["name"].str.lower() == cardname.lower()]
|
38 |
if english_match.shape[0] > 0:
|
39 |
legal = True
|
40 |
cardname_en_list = english_match["name"].to_list()
|
41 |
cardname_ja_list = english_match["name_ja"].to_list()
|
|
|
42 |
japanese_match = mslist_df[mslist_df["name_ja"] == cardname]
|
43 |
if japanese_match.shape[0] > 0:
|
44 |
legal = True
|
45 |
cardname_en_list = japanese_match["name"].to_list()
|
46 |
cardname_ja_list = japanese_match["name_ja"].to_list()
|
|
|
47 |
if len(cardname_en_list) > 0:
|
48 |
legalname_en = cardname_en_list[0]
|
49 |
else:
|
@@ -52,11 +48,11 @@ def get_legal_cardnames(cardname: str, mslist_df: pd.DataFrame) -> list:
|
|
52 |
legalname_ja = cardname_ja_list[0]
|
53 |
else:
|
54 |
legalname_ja = cardname
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
]
|
60 |
|
61 |
|
62 |
def remove_number_of_copies(line: str) -> str:
|
@@ -78,14 +74,6 @@ def is_cardname_legal(cardname: str, mslist_df: pd.DataFrame) -> bool:
|
|
78 |
return False
|
79 |
|
80 |
|
81 |
-
def legal_to_checkmark(row: pd.DataFrame) -> pd.DataFrame:
|
82 |
-
if row["islegal"]:
|
83 |
-
row["Legal"] = "✅"
|
84 |
-
return row
|
85 |
-
row["Legal"] = "🚫"
|
86 |
-
return row
|
87 |
-
|
88 |
-
|
89 |
def split_names_list(row: pd.DataFrame):
|
90 |
"""Splits the English and Japanese card names in a list into two different columns"""
|
91 |
if not isinstance(row["legalnames"], list):
|
@@ -94,4 +82,5 @@ def split_names_list(row: pd.DataFrame):
|
|
94 |
row["English"] = row["legalnames"][1]
|
95 |
if row["legalnames"][1] is not None:
|
96 |
row["日本語"] = row["legalnames"][2]
|
|
|
97 |
return row
|
|
|
9 |
return f"https://scryfall.com/search?q=prefer%3Aoldest%20!%22{urllib.parse.quote_plus(cardname)}%22"
|
10 |
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
def row_to_button_link(row: pd.DataFrame) -> None:
|
13 |
"""Prints a list item with a Scryfall link for the card in the row passed"""
|
14 |
cardname = row.English
|
|
|
25 |
return [False, [], []]
|
26 |
cardname_en_list = []
|
27 |
cardname_ja_list = []
|
28 |
+
banned_list = []
|
29 |
legal = False
|
30 |
+
banned = False
|
31 |
english_match = mslist_df[mslist_df["name"].str.lower() == cardname.lower()]
|
32 |
if english_match.shape[0] > 0:
|
33 |
legal = True
|
34 |
cardname_en_list = english_match["name"].to_list()
|
35 |
cardname_ja_list = english_match["name_ja"].to_list()
|
36 |
+
banned_list = english_match["banned"].to_list()
|
37 |
japanese_match = mslist_df[mslist_df["name_ja"] == cardname]
|
38 |
if japanese_match.shape[0] > 0:
|
39 |
legal = True
|
40 |
cardname_en_list = japanese_match["name"].to_list()
|
41 |
cardname_ja_list = japanese_match["name_ja"].to_list()
|
42 |
+
banned_list = japanese_match["banned"].to_list()
|
43 |
if len(cardname_en_list) > 0:
|
44 |
legalname_en = cardname_en_list[0]
|
45 |
else:
|
|
|
48 |
legalname_ja = cardname_ja_list[0]
|
49 |
else:
|
50 |
legalname_ja = cardname
|
51 |
+
if len(banned_list) > 0:
|
52 |
+
banned = banned_list[0]
|
53 |
+
else:
|
54 |
+
banned = False
|
55 |
+
return [legal, legalname_en, legalname_ja, banned]
|
56 |
|
57 |
|
58 |
def remove_number_of_copies(line: str) -> str:
|
|
|
74 |
return False
|
75 |
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
def split_names_list(row: pd.DataFrame):
|
78 |
"""Splits the English and Japanese card names in a list into two different columns"""
|
79 |
if not isinstance(row["legalnames"], list):
|
|
|
82 |
row["English"] = row["legalnames"][1]
|
83 |
if row["legalnames"][1] is not None:
|
84 |
row["日本語"] = row["legalnames"][2]
|
85 |
+
row["isbanned"] = row["legalnames"][3]
|
86 |
return row
|
streamlit_common/locale.py
CHANGED
@@ -46,6 +46,10 @@ def get_locale():
|
|
46 |
"en": "is an exact match.",
|
47 |
"ja": "が完全一致します。",
|
48 |
},
|
|
|
|
|
|
|
|
|
49 |
"search_by_color": {
|
50 |
"en": "Color:",
|
51 |
"ja": "色:",
|
@@ -63,8 +67,8 @@ def get_locale():
|
|
63 |
"ja": "タフネス:",
|
64 |
},
|
65 |
"cards_found": {
|
66 |
-
"en": " cards were found.",
|
67 |
-
"ja": "枚
|
68 |
},
|
69 |
"top_results": {
|
70 |
"en": "Top results:",
|
@@ -79,6 +83,20 @@ def get_locale():
|
|
79 |
"ja": "上位20枚表示に戻す",
|
80 |
},
|
81 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
"check": {
|
83 |
"title": {
|
84 |
"en": "List Check",
|
|
|
46 |
"en": "is an exact match.",
|
47 |
"ja": "が完全一致します。",
|
48 |
},
|
49 |
+
"banned_match": {
|
50 |
+
"en": "is an exact match, but it is banned.",
|
51 |
+
"ja": "が完全一致しますが、使用禁止になっています。",
|
52 |
+
},
|
53 |
"search_by_color": {
|
54 |
"en": "Color:",
|
55 |
"ja": "色:",
|
|
|
67 |
"ja": "タフネス:",
|
68 |
},
|
69 |
"cards_found": {
|
70 |
+
"en": " cards were found in the card pool.",
|
71 |
+
"ja": "枚 のカードがカードプール見つかりました。",
|
72 |
},
|
73 |
"top_results": {
|
74 |
"en": "Top results:",
|
|
|
83 |
"ja": "上位20枚表示に戻す",
|
84 |
},
|
85 |
},
|
86 |
+
"legality": {
|
87 |
+
"legal": {
|
88 |
+
"en": "Legal",
|
89 |
+
"ja": "使用可能",
|
90 |
+
},
|
91 |
+
"banned": {
|
92 |
+
"en": "Banned",
|
93 |
+
"ja": "禁止カード",
|
94 |
+
},
|
95 |
+
"not_legal": {
|
96 |
+
"en": "Not legal",
|
97 |
+
"ja": "使用不可",
|
98 |
+
},
|
99 |
+
},
|
100 |
"check": {
|
101 |
"title": {
|
102 |
"en": "List Check",
|