Alejandro Cremades commited on
Commit
418e5f7
2 Parent(s): d472752 81025f5

Merge pull request #35 from alecrem/feature/issue-34/notify-exact-match

Browse files
Files changed (1) hide show
  1. Middle_School_Card_Search.py +34 -4
Middle_School_Card_Search.py CHANGED
@@ -4,12 +4,34 @@ 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"
@@ -32,7 +54,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 +64,13 @@ 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
+ cardname = x["name"]
13
+ if x.name_ja is not "":
14
+ cardname = f"{cardname} / {x.name_ja}"
15
+ st.markdown(f"- [{cardname}]({x.link})")
16
+
17
+
18
+ def is_legal(cardname: str) -> list:
19
+ english_match = mslist_df[mslist_df["name"].str.lower() == cardname.lower()]
20
+ cardname_en_list = None
21
+ if english_match.shape[0] > 0:
22
+ cardname_en_list = english_match["name"].to_list()
23
+ cardname_ja_list = english_match["name_ja"].to_list()
24
+ japanese_match = mslist_df[mslist_df["name_ja"] == cardname]
25
+ if japanese_match.shape[0] > 0:
26
+ cardname_en_list = japanese_match["name"].to_list()
27
+ cardname_ja_list = japanese_match["name_ja"].to_list()
28
+ if cardname_en_list is not None and len(cardname_en_list) > 0:
29
+ return [
30
+ cardname_en_list[0] or None,
31
+ cardname_ja_list[0] or None,
32
+ ]
33
+
34
+ return None
35
 
36
 
37
  mslist_path = "output/middleschool.csv"
 
54
  mslist_df.fillna("", inplace=True)
55
  st.write(mslist_df.shape[0], "cards are legal")
56
 
57
+ name_input = st.text_input(f"Search by card name").strip()
58
+ exact_match = is_legal(name_input)
59
  results_en_df = mslist_df[
60
  mslist_df["name"].str.contains(name_input.lower(), case=False)
61
  ]
 
64
  ]
65
  results_df = results_en_df.merge(results_ja_df, how="outer")
66
  if name_input:
67
+ if exact_match is not None:
68
+ cardname = exact_match[0]
69
+ if exact_match[1] is not None:
70
+ cardname = f"{cardname} / {exact_match[1]}"
71
+ st.write(
72
+ f"✅ [{cardname}]({compose_scryfall_url(exact_match[0])}) is an exact match"
73
+ )
74
  st.write(results_df.shape[0], f'cards found by "{name_input}"')
75
  if results_df.shape[0] > number_shown_results:
76
  st.write(f"Top {number_shown_results} results:")