Alejandro Cremades commited on
Commit
ea3872d
1 Parent(s): d472752

Notify the user if their card search was an exact match

Browse files
Files changed (1) hide show
  1. Middle_School_Card_Search.py +18 -3
Middle_School_Card_Search.py CHANGED
@@ -4,14 +4,24 @@ import urllib.parse
4
  import streamlit_common.footer
5
 
6
 
7
- def compose_scryfall_url(x):
8
  return f"https://scryfall.com/search?q=prefer%3Aoldest%20!%22{urllib.parse.quote_plus(x)}%22"
9
 
10
 
11
- def row_to_link(x):
12
  st.markdown(f"- [{x['name']} / {x.name_ja}]({x.link})")
13
 
14
 
 
 
 
 
 
 
 
 
 
 
15
  mslist_path = "output/middleschool.csv"
16
  number_shown_results = 20
17
 
@@ -32,7 +42,8 @@ mslist_df = pd.read_csv(mslist_path)
32
  mslist_df.fillna("", inplace=True)
33
  st.write(mslist_df.shape[0], "cards are legal")
34
 
35
- name_input = st.text_input(f"Search by card name")
 
36
  results_en_df = mslist_df[
37
  mslist_df["name"].str.contains(name_input.lower(), case=False)
38
  ]
@@ -41,6 +52,10 @@ results_ja_df = mslist_df[
41
  ]
42
  results_df = results_en_df.merge(results_ja_df, how="outer")
43
  if name_input:
 
 
 
 
44
  st.write(results_df.shape[0], f'cards found by "{name_input}"')
45
  if results_df.shape[0] > number_shown_results:
46
  st.write(f"Top {number_shown_results} results:")
 
4
  import streamlit_common.footer
5
 
6
 
7
+ def compose_scryfall_url(x: str) -> str:
8
  return f"https://scryfall.com/search?q=prefer%3Aoldest%20!%22{urllib.parse.quote_plus(x)}%22"
9
 
10
 
11
+ def row_to_link(x: pd.DataFrame) -> None:
12
  st.markdown(f"- [{x['name']} / {x.name_ja}]({x.link})")
13
 
14
 
15
+ def is_legal(cardname: str) -> str:
16
+ english_match = mslist_df[mslist_df["name"].str.lower() == cardname.lower()]
17
+ if english_match.shape[0] > 0:
18
+ return english_match["name"].to_list()[0]
19
+ japanese_match = mslist_df[mslist_df["name_ja"] == cardname]
20
+ if japanese_match.shape[0] > 0:
21
+ return japanese_match["name_ja"].to_list()[0]
22
+ return None
23
+
24
+
25
  mslist_path = "output/middleschool.csv"
26
  number_shown_results = 20
27
 
 
42
  mslist_df.fillna("", inplace=True)
43
  st.write(mslist_df.shape[0], "cards are legal")
44
 
45
+ name_input = st.text_input(f"Search by card name").strip()
46
+ exact_match = is_legal(name_input)
47
  results_en_df = mslist_df[
48
  mslist_df["name"].str.contains(name_input.lower(), case=False)
49
  ]
 
52
  ]
53
  results_df = results_en_df.merge(results_ja_df, how="outer")
54
  if name_input:
55
+ if exact_match is not None:
56
+ st.write(
57
+ f"✅ [{exact_match}]({compose_scryfall_url(exact_match)}) is an exact match"
58
+ )
59
  st.write(results_df.shape[0], f'cards found by "{name_input}"')
60
  if results_df.shape[0] > number_shown_results:
61
  st.write(f"Top {number_shown_results} results:")