Spaces:
Running
Running
Alejandro Cremades
commited on
Commit
•
dfa94a9
1
Parent(s):
14f90e3
Document the functions
Browse files- streamlit_common/lib.py +16 -7
streamlit_common/lib.py
CHANGED
@@ -4,18 +4,23 @@ import re
|
|
4 |
import urllib.parse
|
5 |
|
6 |
|
7 |
-
def compose_scryfall_url(
|
8 |
-
|
|
|
9 |
|
10 |
|
11 |
-
def row_to_link(
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
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:
|
@@ -34,6 +39,9 @@ def get_legal_cardnames(cardname: str, mslist_df: pd.DataFrame) -> list:
|
|
34 |
|
35 |
|
36 |
def remove_number_of_copies(line: str) -> str:
|
|
|
|
|
|
|
37 |
if len(line.strip()) < 1:
|
38 |
return None
|
39 |
pattern = re.compile("^([0-9]+) +")
|
@@ -41,6 +49,7 @@ def remove_number_of_copies(line: str) -> str:
|
|
41 |
|
42 |
|
43 |
def is_cardname_legal(cardname: str, mslist_df: pd.DataFrame) -> bool:
|
|
|
44 |
if mslist_df[mslist_df["name"].str.lower() == cardname.lower()].shape[0] > 0:
|
45 |
return True
|
46 |
if mslist_df[mslist_df["name_ja"] == cardname].shape[0] > 0:
|
|
|
4 |
import urllib.parse
|
5 |
|
6 |
|
7 |
+
def compose_scryfall_url(cardname: str) -> str:
|
8 |
+
"""Compose a Scryfall URL from the passed card name"""
|
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.markdown(f"- [{cardname}]({row.link})")
|
18 |
|
19 |
|
20 |
def get_legal_cardnames(cardname: str, mslist_df: pd.DataFrame) -> list:
|
21 |
+
"""Returns a list with the English and Japanese names for the card
|
22 |
+
if there is an exact match, or `None` if there is not.
|
23 |
+
"""
|
24 |
english_match = mslist_df[mslist_df["name"].str.lower() == cardname.lower()]
|
25 |
cardname_en_list = None
|
26 |
if english_match.shape[0] > 0:
|
|
|
39 |
|
40 |
|
41 |
def remove_number_of_copies(line: str) -> str:
|
42 |
+
"""Remove the number of copies in front of the card name
|
43 |
+
from a line in a card list
|
44 |
+
"""
|
45 |
if len(line.strip()) < 1:
|
46 |
return None
|
47 |
pattern = re.compile("^([0-9]+) +")
|
|
|
49 |
|
50 |
|
51 |
def is_cardname_legal(cardname: str, mslist_df: pd.DataFrame) -> bool:
|
52 |
+
"""Returns wether a card with exactly the passed name is legal in the format"""
|
53 |
if mslist_df[mslist_df["name"].str.lower() == cardname.lower()].shape[0] > 0:
|
54 |
return True
|
55 |
if mslist_df[mslist_df["name_ja"] == cardname].shape[0] > 0:
|