mirror of
https://github.com/mwisnowski/mtg_python_deckbuilder.git
synced 2025-12-17 08:00:13 +01:00
feat: refresh theme catalog metadata
This commit is contained in:
parent
ca2ef70c23
commit
33570399f0
5 changed files with 19290 additions and 1134 deletions
|
|
@ -27,6 +27,7 @@ from collections import Counter
|
|||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional, Set, Tuple
|
||||
import re
|
||||
|
||||
try: # Optional
|
||||
import yaml # type: ignore
|
||||
|
|
@ -64,6 +65,20 @@ except ModuleNotFoundError:
|
|||
should_keep_theme,
|
||||
)
|
||||
|
||||
try:
|
||||
from scripts.export_themes_to_yaml import slugify as slugify_theme # type: ignore
|
||||
except Exception:
|
||||
_SLUG_RE = re.compile(r'[^a-z0-9-]')
|
||||
|
||||
def slugify_theme(name: str) -> str:
|
||||
s = name.strip().lower()
|
||||
s = s.replace('+', 'plus')
|
||||
s = s.replace('/', '-')
|
||||
s = re.sub(r'[\s_]+', '-', s)
|
||||
s = _SLUG_RE.sub('', s)
|
||||
s = re.sub(r'-{2,}', '-', s)
|
||||
return s.strip('-')
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
CODE_ROOT = ROOT / 'code'
|
||||
if str(CODE_ROOT) not in sys.path:
|
||||
|
|
@ -729,7 +744,8 @@ def build_catalog(limit: int, verbose: bool) -> Dict[str, Any]:
|
|||
else:
|
||||
primary, secondary = _primary_secondary(theme, analytics['frequencies'])
|
||||
|
||||
entry = {'theme': theme, 'synergies': merged}
|
||||
slug = getattr(y, 'id', None) or slugify_theme(theme)
|
||||
entry = {'id': slug, 'theme': theme, 'synergies': merged}
|
||||
if primary:
|
||||
entry['primary_color'] = primary
|
||||
if secondary:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue