Update trade listings
This commit is contained in:
@@ -13,6 +13,7 @@ import csv
|
||||
from pathlib import Path
|
||||
import re
|
||||
from statistics import median
|
||||
import unicodedata
|
||||
|
||||
from discord_trade_parser import KNOWN_UNIT_NAMES, normalize_unit_names
|
||||
|
||||
@@ -20,7 +21,12 @@ from discord_trade_parser import KNOWN_UNIT_NAMES, normalize_unit_names
|
||||
UNIT_NAMES = tuple(
|
||||
name for name in KNOWN_UNIT_NAMES if name.casefold() != "shiny skull knight"
|
||||
)
|
||||
CANONICAL_NAMES = {name.casefold(): normalize_unit_names(name) for name in UNIT_NAMES}
|
||||
def canonical_key(name: str) -> str:
|
||||
return "".join(char for char in unicodedata.normalize("NFKD", name.casefold())
|
||||
if not unicodedata.combining(char))
|
||||
|
||||
|
||||
CANONICAL_NAMES = {canonical_key(name): normalize_unit_names(name) for name in UNIT_NAMES}
|
||||
UNIT_PATTERN = re.compile(
|
||||
r"(?<!\w)(?P<shiny>Shiny\s+)?(?P<unit>"
|
||||
+ "|".join(re.escape(name).replace(r"\ ", r"\s+") for name in UNIT_NAMES)
|
||||
@@ -36,7 +42,7 @@ def variants(text: str, *, request: bool = False) -> set[str]:
|
||||
for match in UNIT_PATTERN.finditer(text):
|
||||
if request and MY_PREFIX.search(text[max(0, match.start() - 12):match.start()]):
|
||||
continue
|
||||
name = CANONICAL_NAMES[match.group("unit").casefold()]
|
||||
name = CANONICAL_NAMES[canonical_key(match.group("unit"))]
|
||||
shiny = "Shiny " if match.group("shiny") else ""
|
||||
evolution = match.group("evolution").capitalize()
|
||||
found.add(f"{shiny}{name} {evolution}")
|
||||
|
||||
Reference in New Issue
Block a user