Alejandro Cremades commited on
Commit
2714786
1 Parent(s): 418e5f7

Refactor previous is_legal functions

Browse files
Middle_School_Card_Search.py CHANGED
@@ -15,7 +15,7 @@ def row_to_link(x: pd.DataFrame) -> None:
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:
@@ -30,7 +30,6 @@ def is_legal(cardname: str) -> list:
30
  cardname_en_list[0] or None,
31
  cardname_ja_list[0] or None,
32
  ]
33
-
34
  return None
35
 
36
 
@@ -55,7 +54,7 @@ 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
  ]
 
15
  st.markdown(f"- [{cardname}]({x.link})")
16
 
17
 
18
+ def get_legal_cardnames(cardname: str, mslist_df: pd.DataFrame) -> 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:
 
30
  cardname_en_list[0] or None,
31
  cardname_ja_list[0] or None,
32
  ]
 
33
  return None
34
 
35
 
 
54
  st.write(mslist_df.shape[0], "cards are legal")
55
 
56
  name_input = st.text_input(f"Search by card name").strip()
57
+ exact_match = get_legal_cardnames(name_input, mslist_df)
58
  results_en_df = mslist_df[
59
  mslist_df["name"].str.contains(name_input.lower(), case=False)
60
  ]
pages/1_Check_Card_List.py CHANGED
@@ -11,7 +11,7 @@ def remove_number_of_copies(line: str) -> str:
11
  return pattern.sub("", line)
12
 
13
 
14
- def is_legal(cardname: str) -> bool:
15
  if mslist_df[mslist_df["name"].str.lower() == cardname.lower()].shape[0] > 0:
16
  return True
17
  if mslist_df[mslist_df["name_ja"] == cardname].shape[0] > 0:
@@ -51,7 +51,9 @@ for line in input_list.split("\n"):
51
  cardnames.append(remove_number_of_copies(cardname))
52
 
53
  input_cards = pd.DataFrame(cardnames, columns=["cardname"])
54
- input_cards["legal"] = input_cards["cardname"].apply(is_legal)
 
 
55
 
56
  col2.write("##### Middle School legality")
57
  col2.dataframe(input_cards[["legal", "cardname"]], use_container_width=True)
 
11
  return pattern.sub("", line)
12
 
13
 
14
+ def is_cardname_legal(cardname: str, mslist_df: pd.DataFrame) -> bool:
15
  if mslist_df[mslist_df["name"].str.lower() == cardname.lower()].shape[0] > 0:
16
  return True
17
  if mslist_df[mslist_df["name_ja"] == cardname].shape[0] > 0:
 
51
  cardnames.append(remove_number_of_copies(cardname))
52
 
53
  input_cards = pd.DataFrame(cardnames, columns=["cardname"])
54
+ input_cards["legal"] = input_cards["cardname"].apply(
55
+ is_cardname_legal, args=[mslist_df]
56
+ )
57
 
58
  col2.write("##### Middle School legality")
59
  col2.dataframe(input_cards[["legal", "cardname"]], use_container_width=True)