Spaces:
Running
Running
File size: 2,094 Bytes
14f90e3 dfa94a9 14f90e3 dfa94a9 14f90e3 dfa94a9 14f90e3 dfa94a9 14f90e3 dfa94a9 14f90e3 |
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 |
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.markdown(f"- [{cardname}]({row.link})")
def get_legal_cardnames(cardname: str, mslist_df: pd.DataFrame) -> list:
"""Returns a list with the English and Japanese names for the card
if there is an exact match, or `None` if there is not.
"""
english_match = mslist_df[mslist_df["name"].str.lower() == cardname.lower()]
cardname_en_list = None
if english_match.shape[0] > 0:
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:
cardname_en_list = japanese_match["name"].to_list()
cardname_ja_list = japanese_match["name_ja"].to_list()
if cardname_en_list is not None and len(cardname_en_list) > 0:
return [
cardname_en_list[0] or None,
cardname_ja_list[0] or None,
]
return None
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
|