Alejandro Cremades commited on
Commit
a807ea9
β€’
1 Parent(s): 448e881

Check legality of all cards in list

Browse files
Files changed (1) hide show
  1. pages/1_Check_Card_List.py +49 -0
pages/1_Check_Card_List.py CHANGED
@@ -1,7 +1,56 @@
1
  import streamlit as st
 
 
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  st.write(
4
  """
5
  # Middle School List Check
 
 
6
  """
7
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import pandas as pd
3
+ import re
4
 
5
+
6
+ def remove_number_of_copies(line: str) -> str:
7
+ if len(line.strip()) < 1:
8
+ return None
9
+ pattern = re.compile("^([0-9]+) +")
10
+ return pattern.sub("", line)
11
+
12
+
13
+ def is_legal(cardname: str) -> bool:
14
+ if mslist_df[mslist_df["name"].str.lower() == cardname.lower()].shape[0] > 0:
15
+ return True
16
+ if mslist_df[mslist_df["name_ja"] == cardname].shape[0] > 0:
17
+ return True
18
+ return False
19
+
20
+
21
+ mslist_path = "output/middleschool.csv"
22
+
23
+ st.set_page_config(
24
+ page_title="Middle School | Check Card List",
25
+ page_icon="πŸƒ",
26
+ layout="wide",
27
+ )
28
  st.write(
29
  """
30
  # Middle School List Check
31
+
32
+ Paste or type your list here to confirm that every card in it is Middle School legal.
33
  """
34
  )
35
+
36
+ mslist_df = pd.read_csv(mslist_path)
37
+ mslist_df.fillna("", inplace=True)
38
+
39
+ col1, col2 = st.columns(2)
40
+
41
+ input_list = col1.text_area(
42
+ label="##### Card list", placeholder="4 Lightning Bolt\n4 γƒœγƒΌγƒ«γƒ»γƒ©γ‚€γƒˆγƒ‹γƒ³γ‚°", height=400
43
+ )
44
+
45
+ cardnames = []
46
+
47
+ for line in input_list.split("\n"):
48
+ cardname = remove_number_of_copies(line)
49
+ if cardname is not None:
50
+ cardnames.append(remove_number_of_copies(cardname))
51
+
52
+ input_cards = pd.DataFrame(cardnames, columns=["name"])
53
+ input_cards["legal"] = input_cards["name"].apply(is_legal)
54
+
55
+ col2.write("##### Middle School legality")
56
+ col2.dataframe(input_cards, use_container_width=True)