File size: 3,264 Bytes
14f90e3
 
 
 
 
 
dfa94a9
 
 
14f90e3
 
dfa94a9
 
 
 
 
6085806
14f90e3
 
df9758b
 
 
 
 
6085806
df9758b
 
14f90e3
82116f7
 
dfa94a9
24d3971
 
82116f7
 
 
14f90e3
 
82116f7
14f90e3
 
 
 
82116f7
14f90e3
 
82116f7
 
 
 
 
 
 
 
 
 
 
 
 
14f90e3
 
 
dfa94a9
 
 
14f90e3
 
 
 
 
 
 
dfa94a9
14f90e3
 
 
 
 
d3537a9
 
82116f7
 
 
 
 
 
 
 
d3537a9
 
 
 
82116f7
 
d3537a9
82116f7
d3537a9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import streamlit as st
import pandas as pd
import re
import urllib.parse


def compose_scryfall_url(cardname: str) -> str:
    """Compose a Scryfall URL from the passed card name"""
    return f"https://scryfall.com/search?q=prefer%3Aoldest%20!%22{urllib.parse.quote_plus(cardname)}%22"


def row_to_link(row: pd.DataFrame) -> None:
    """Prints a list item with a Scryfall link for the card in the row passed"""
    cardname = row["name"]
    if row.name_ja is not "":
        cardname = f"{cardname} / {row.name_ja}"
    st.write(f"- [{cardname}]({row.link})")


def row_to_button_link(row: pd.DataFrame) -> None:
    """Prints a list item with a Scryfall link for the card in the row passed"""
    cardname = row.English
    if row.日本語 is not "":
        cardname = f"{cardname} / {row.日本語}"
    st.write(f"- [{cardname}]({compose_scryfall_url(row.English)})")


def get_legal_cardnames(cardname: str, mslist_df: pd.DataFrame) -> list:
    """Returns a list with legality (boolean) plus the English and Japanese
    names for the card if there is an exact match, or the user's input if there is not.
    """
    if len(cardname) < 1:
        return [False, [], []]
    cardname_en_list = []
    cardname_ja_list = []
    legal = False
    english_match = mslist_df[mslist_df["name"].str.lower() == cardname.lower()]
    if english_match.shape[0] > 0:
        legal = True
        cardname_en_list = english_match["name"].to_list()
        cardname_ja_list = english_match["name_ja"].to_list()
    japanese_match = mslist_df[mslist_df["name_ja"] == cardname]
    if japanese_match.shape[0] > 0:
        legal = True
        cardname_en_list = japanese_match["name"].to_list()
        cardname_ja_list = japanese_match["name_ja"].to_list()
    if len(cardname_en_list) > 0:
        legalname_en = cardname_en_list[0]
    else:
        legalname_en = cardname
    if len(cardname_ja_list) > 0:
        legalname_ja = cardname_ja_list[0]
    else:
        legalname_ja = cardname
    return [
        legal,
        legalname_en,
        legalname_ja,
    ]


def remove_number_of_copies(line: str) -> str:
    """Remove the number of copies in front of the card name
    from a line in a card list
    """
    if len(line.strip()) < 1:
        return None
    pattern = re.compile("^([0-9]+) +")
    return pattern.sub("", line)


def is_cardname_legal(cardname: str, mslist_df: pd.DataFrame) -> bool:
    """Returns wether a card with exactly the passed name is legal in the format"""
    if mslist_df[mslist_df["name"].str.lower() == cardname.lower()].shape[0] > 0:
        return True
    if mslist_df[mslist_df["name_ja"] == cardname].shape[0] > 0:
        return True
    return False


def legal_to_checkmark(row: pd.DataFrame) -> pd.DataFrame:
    if row["islegal"]:
        row["Legal"] = "✅"
        return row
    row["Legal"] = "🚫"
    return row


def split_names_list(row: pd.DataFrame):
    """Splits the English and Japanese card names in a list into two different columns"""
    if not isinstance(row["legalnames"], list):
        return row
    row["islegal"] = row["legalnames"][0]
    row["English"] = row["legalnames"][1]
    if row["legalnames"][1] is not None:
        row["日本語"] = row["legalnames"][2]
    return row