mirror of
https://github.com/mwisnowski/mtg_python_deckbuilder.git
synced 2025-09-21 20:40:47 +02:00
chore(release): v1.1.2 bump, notes/template + README updates, Docker Hub description updater, headless/docs tweaks
This commit is contained in:
parent
fd2530cea3
commit
5f922835a6
13 changed files with 250 additions and 183 deletions
|
@ -74,12 +74,36 @@ class DeckBuilder(
|
|||
try:
|
||||
# Ensure CSVs exist and are tagged before starting any deck build logic
|
||||
try:
|
||||
import time as _time
|
||||
import json as _json
|
||||
from datetime import datetime as _dt
|
||||
cards_path = os.path.join(CSV_DIRECTORY, 'cards.csv')
|
||||
flag_path = os.path.join(CSV_DIRECTORY, '.tagging_complete.json')
|
||||
refresh_needed = False
|
||||
if not os.path.exists(cards_path):
|
||||
logger.info("cards.csv not found. Running initial setup and tagging before deck build...")
|
||||
refresh_needed = True
|
||||
else:
|
||||
try:
|
||||
age_seconds = _time.time() - os.path.getmtime(cards_path)
|
||||
if age_seconds > 7 * 24 * 60 * 60:
|
||||
logger.info("cards.csv is older than 7 days. Refreshing data before deck build...")
|
||||
refresh_needed = True
|
||||
except Exception:
|
||||
pass
|
||||
if not os.path.exists(flag_path):
|
||||
logger.info("Tagging completion flag not found. Performing full tagging before deck build...")
|
||||
refresh_needed = True
|
||||
if refresh_needed:
|
||||
initial_setup()
|
||||
from tagging import tagger
|
||||
tagger.run_tagging()
|
||||
from tagging import tagger as _tagger
|
||||
_tagger.run_tagging()
|
||||
try:
|
||||
os.makedirs(CSV_DIRECTORY, exist_ok=True)
|
||||
with open(flag_path, 'w', encoding='utf-8') as _fh:
|
||||
_json.dump({'tagged_at': _dt.now().isoformat(timespec='seconds')}, _fh)
|
||||
except Exception:
|
||||
logger.warning("Failed to write tagging completion flag (non-fatal).")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed ensuring CSVs before deck build: {e}")
|
||||
self.run_initial_setup()
|
||||
|
|
|
@ -4,50 +4,30 @@ import argparse
|
|||
import json
|
||||
import os
|
||||
from typing import Any, Dict, List, Optional
|
||||
from pathlib import Path
|
||||
|
||||
from deck_builder.builder import DeckBuilder
|
||||
|
||||
"""Headless (non-interactive) runner.
|
||||
|
||||
Features:
|
||||
- Script commander selection.
|
||||
- Script primary / optional secondary / tertiary tags.
|
||||
- Apply bracket & accept default ideal counts.
|
||||
- Invoke multi-theme creature addition if available (fallback to primary-only).
|
||||
|
||||
Use run(..., secondary_choice=2, tertiary_choice=3, use_multi_theme=True) to exercise multi-theme logic.
|
||||
Indices correspond to the numbered tag list presented during interaction.
|
||||
"""
|
||||
|
||||
def run(
|
||||
command_name: str = "Pantlaza",
|
||||
command_name: str = "",
|
||||
add_creatures: bool = True,
|
||||
add_non_creature_spells: bool = True,
|
||||
# Fine-grained toggles (used only if add_non_creature_spells is False)
|
||||
add_ramp: bool = True,
|
||||
add_removal: bool = True,
|
||||
add_wipes: bool = True,
|
||||
add_card_advantage: bool = True,
|
||||
add_protection: bool = True,
|
||||
use_multi_theme: bool = True,
|
||||
primary_choice: int = 2,
|
||||
secondary_choice: Optional[int] = 2,
|
||||
tertiary_choice: Optional[int] = 2,
|
||||
primary_choice: int = 1,
|
||||
secondary_choice: Optional[int] = None,
|
||||
tertiary_choice: Optional[int] = None,
|
||||
add_lands: bool = True,
|
||||
fetch_count: Optional[int] = 3,
|
||||
dual_count: Optional[int] = None,
|
||||
triple_count: Optional[int] = None,
|
||||
utility_count: Optional[int] = None,
|
||||
ideal_counts: Optional[Dict[str, int]] = None,
|
||||
bracket_level: Optional[int] = None,
|
||||
) -> DeckBuilder:
|
||||
"""Run a scripted non-interactive deck build and return the DeckBuilder instance.
|
||||
|
||||
Integer parameters (primary_choice, secondary_choice, tertiary_choice) correspond to the
|
||||
numeric indices shown during interactive tag selection. Pass None to omit secondary/tertiary.
|
||||
Optional counts (fetch_count, dual_count, triple_count, utility_count) constrain land steps.
|
||||
|
||||
"""
|
||||
"""Run a scripted non-interactive deck build and return the DeckBuilder instance."""
|
||||
scripted_inputs: List[str] = []
|
||||
# Commander query & selection
|
||||
scripted_inputs.append(command_name) # initial query
|
||||
|
@ -65,8 +45,8 @@ def run(
|
|||
scripted_inputs.append("0")
|
||||
else:
|
||||
scripted_inputs.append("0") # stop at primary
|
||||
# Bracket (meta power / style) selection; keeping existing scripted value
|
||||
scripted_inputs.append("3")
|
||||
# Bracket (meta power / style) selection; default to 3 if not provided
|
||||
scripted_inputs.append(str(bracket_level if isinstance(bracket_level, int) and 1 <= bracket_level <= 5 else 3))
|
||||
# Ideal count prompts (press Enter for defaults)
|
||||
for _ in range(8):
|
||||
scripted_inputs.append("")
|
||||
|
@ -107,84 +87,88 @@ def run(
|
|||
|
||||
# Land sequence (optional)
|
||||
if add_lands:
|
||||
if hasattr(builder, 'run_land_step1'):
|
||||
builder.run_land_step1() # Basics / initial
|
||||
if hasattr(builder, 'run_land_step2'):
|
||||
builder.run_land_step2() # Utility basics / rebalancing
|
||||
if hasattr(builder, 'run_land_step3'):
|
||||
builder.run_land_step3() # Kindred lands if applicable
|
||||
if hasattr(builder, 'run_land_step4'):
|
||||
builder.run_land_step4(requested_count=fetch_count)
|
||||
if hasattr(builder, 'run_land_step5'):
|
||||
builder.run_land_step5(requested_count=dual_count)
|
||||
if hasattr(builder, 'run_land_step6'):
|
||||
builder.run_land_step6(requested_count=triple_count)
|
||||
if hasattr(builder, 'run_land_step7'):
|
||||
|
||||
builder.run_land_step7(requested_count=utility_count)
|
||||
if hasattr(builder, 'run_land_step8'):
|
||||
builder.run_land_step8()
|
||||
def call(method: str, **kwargs: Any) -> None:
|
||||
fn = getattr(builder, method, None)
|
||||
if callable(fn):
|
||||
try:
|
||||
fn(**kwargs)
|
||||
except Exception:
|
||||
pass
|
||||
for method, kwargs in [
|
||||
("run_land_step1", {}),
|
||||
("run_land_step2", {}),
|
||||
("run_land_step3", {}),
|
||||
("run_land_step4", {"requested_count": fetch_count}),
|
||||
("run_land_step5", {"requested_count": dual_count}),
|
||||
("run_land_step6", {"requested_count": triple_count}),
|
||||
("run_land_step7", {"requested_count": utility_count}),
|
||||
("run_land_step8", {}),
|
||||
]:
|
||||
call(method, **kwargs)
|
||||
|
||||
if add_creatures:
|
||||
builder.add_creatures()
|
||||
# Non-creature spell categories (ramp / removal / wipes / draw / protection)
|
||||
if add_non_creature_spells and hasattr(builder, 'add_non_creature_spells'):
|
||||
builder.add_non_creature_spells()
|
||||
else:
|
||||
# Allow selective invocation if orchestrator not desired
|
||||
if add_ramp and hasattr(builder, 'add_ramp'):
|
||||
builder.add_ramp()
|
||||
if add_removal and hasattr(builder, 'add_removal'):
|
||||
builder.add_removal()
|
||||
if add_wipes and hasattr(builder, 'add_board_wipes'):
|
||||
builder.add_board_wipes()
|
||||
if add_card_advantage and hasattr(builder, 'add_card_advantage'):
|
||||
builder.add_card_advantage()
|
||||
if add_protection and hasattr(builder, 'add_protection'):
|
||||
builder.add_protection()
|
||||
|
||||
|
||||
# Suppress verbose library print in headless run since CSV export is produced.
|
||||
# builder.print_card_library()
|
||||
builder.post_spell_land_adjust()
|
||||
# Export decklist CSV (commander first word + date)
|
||||
csv_path: Optional[str] = None
|
||||
if hasattr(builder, 'export_decklist_csv'):
|
||||
did_bulk = False
|
||||
if add_non_creature_spells and hasattr(builder, "add_non_creature_spells"):
|
||||
try:
|
||||
csv_path = builder.export_decklist_csv()
|
||||
builder.add_non_creature_spells()
|
||||
did_bulk = True
|
||||
except Exception:
|
||||
csv_path = None
|
||||
if hasattr(builder, 'export_decklist_text'):
|
||||
try:
|
||||
if csv_path:
|
||||
base = os.path.splitext(os.path.basename(csv_path))[0]
|
||||
builder.export_decklist_text(filename=base + '.txt')
|
||||
# Headless policy: do NOT export JSON by default. Opt-in with HEADLESS_EXPORT_JSON=1
|
||||
allow_json = (os.getenv('HEADLESS_EXPORT_JSON', '').strip().lower() in {'1','true','yes','on'})
|
||||
if allow_json and hasattr(builder, 'export_run_config_json'):
|
||||
did_bulk = False
|
||||
if not did_bulk:
|
||||
for method, flag in [
|
||||
("add_ramp", add_ramp),
|
||||
("add_removal", add_removal),
|
||||
("add_board_wipes", add_wipes),
|
||||
("add_card_advantage", add_card_advantage),
|
||||
("add_protection", add_protection),
|
||||
]:
|
||||
if flag:
|
||||
fn = getattr(builder, method, None)
|
||||
if callable(fn):
|
||||
try:
|
||||
cfg_path_env = os.getenv('DECK_CONFIG')
|
||||
if cfg_path_env and os.path.isdir(os.path.dirname(cfg_path_env) or '.'):
|
||||
cfg_dir = os.path.dirname(cfg_path_env) or '.'
|
||||
elif os.path.isdir('/app/config'):
|
||||
cfg_dir = '/app/config'
|
||||
else:
|
||||
cfg_dir = 'config'
|
||||
os.makedirs(cfg_dir, exist_ok=True)
|
||||
builder.export_run_config_json(directory=cfg_dir, filename=base + '.json')
|
||||
# If an explicit DECK_CONFIG path is given to a file, write exactly there as well
|
||||
if cfg_path_env and os.path.splitext(cfg_path_env)[1].lower() == '.json':
|
||||
cfg_dir2 = os.path.dirname(cfg_path_env) or '.'
|
||||
cfg_name2 = os.path.basename(cfg_path_env)
|
||||
os.makedirs(cfg_dir2, exist_ok=True)
|
||||
builder.export_run_config_json(directory=cfg_dir2, filename=cfg_name2)
|
||||
fn()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
builder.post_spell_land_adjust()
|
||||
_export_outputs(builder)
|
||||
return builder
|
||||
|
||||
def _should_export_json_headless() -> bool:
|
||||
return os.getenv('HEADLESS_EXPORT_JSON', '').strip().lower() in {'1','true','yes','on'}
|
||||
|
||||
def _export_outputs(builder: DeckBuilder) -> None:
|
||||
csv_path: Optional[str] = None
|
||||
try:
|
||||
csv_path = builder.export_decklist_csv() if hasattr(builder, "export_decklist_csv") else None
|
||||
except Exception:
|
||||
csv_path = None
|
||||
try:
|
||||
if hasattr(builder, "export_decklist_text"):
|
||||
if csv_path:
|
||||
base = os.path.splitext(os.path.basename(csv_path))[0]
|
||||
builder.export_decklist_text(filename=base + ".txt")
|
||||
else:
|
||||
builder.export_decklist_text()
|
||||
except Exception:
|
||||
pass
|
||||
if _should_export_json_headless() and hasattr(builder, "export_run_config_json") and csv_path:
|
||||
try:
|
||||
base = os.path.splitext(os.path.basename(csv_path))[0]
|
||||
dest = os.getenv("DECK_CONFIG")
|
||||
if dest and dest.lower().endswith(".json"):
|
||||
out_dir, out_name = os.path.dirname(dest) or ".", os.path.basename(dest)
|
||||
os.makedirs(out_dir, exist_ok=True)
|
||||
builder.export_run_config_json(directory=out_dir, filename=out_name)
|
||||
else:
|
||||
out_dir = (dest if dest and os.path.isdir(dest) else "config")
|
||||
os.makedirs(out_dir, exist_ok=True)
|
||||
builder.export_run_config_json(directory=out_dir, filename=base + ".json")
|
||||
except Exception:
|
||||
pass
|
||||
return builder
|
||||
|
||||
def _parse_bool(val: Optional[str | bool | int]) -> Optional[bool]:
|
||||
if val is None:
|
||||
|
@ -232,6 +216,7 @@ def _build_arg_parser() -> argparse.ArgumentParser:
|
|||
p.add_argument("--primary-choice", type=int, default=None)
|
||||
p.add_argument("--secondary-choice", type=_parse_opt_int, default=None)
|
||||
p.add_argument("--tertiary-choice", type=_parse_opt_int, default=None)
|
||||
p.add_argument("--bracket-level", type=int, default=None)
|
||||
p.add_argument("--add-lands", type=_parse_bool, default=None)
|
||||
p.add_argument("--fetch-count", type=_parse_opt_int, default=None)
|
||||
p.add_argument("--dual-count", type=_parse_opt_int, default=None)
|
||||
|
@ -246,9 +231,7 @@ def _build_arg_parser() -> argparse.ArgumentParser:
|
|||
p.add_argument("--add-wipes", type=_parse_bool, default=None)
|
||||
p.add_argument("--add-card-advantage", type=_parse_bool, default=None)
|
||||
p.add_argument("--add-protection", type=_parse_bool, default=None)
|
||||
p.add_argument("--use-multi-theme", type=_parse_bool, default=None)
|
||||
p.add_argument("--dry-run", action="store_true", help="Print resolved config and exit")
|
||||
p.add_argument("--auto-select-config", action="store_true", help="If set, and multiple JSON configs exist, list and prompt to choose one before running.")
|
||||
return p
|
||||
|
||||
|
||||
|
@ -278,75 +261,27 @@ def _resolve_value(
|
|||
def _main() -> int:
|
||||
parser = _build_arg_parser()
|
||||
args = parser.parse_args()
|
||||
# Optional config auto-discovery/prompting
|
||||
# Optional config discovery (no prompts)
|
||||
cfg_path = args.config
|
||||
json_cfg: Dict[str, Any] = {}
|
||||
def _discover_json_configs() -> List[str]:
|
||||
# Determine directory to scan for JSON configs
|
||||
if cfg_path and os.path.isdir(cfg_path):
|
||||
cfg_dir = cfg_path
|
||||
elif os.path.isdir('/app/config'):
|
||||
cfg_dir = '/app/config'
|
||||
else:
|
||||
cfg_dir = 'config'
|
||||
try:
|
||||
p = Path(cfg_dir)
|
||||
return sorted([str(fp) for fp in p.glob('*.json')]) if p.exists() else []
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
# If a file path is provided, load it directly
|
||||
if cfg_path and os.path.isfile(cfg_path):
|
||||
json_cfg = _load_json_config(cfg_path)
|
||||
else:
|
||||
# If auto-select is requested, we may prompt user to choose a config
|
||||
configs = _discover_json_configs()
|
||||
if cfg_path and os.path.isdir(cfg_path):
|
||||
# Directory explicitly provided, prefer auto selection behavior
|
||||
if len(configs) == 1:
|
||||
json_cfg = _load_json_config(configs[0])
|
||||
os.environ['DECK_CONFIG'] = configs[0]
|
||||
elif len(configs) > 1 and args.auto_select_config:
|
||||
def _label(p: str) -> str:
|
||||
try:
|
||||
with open(p, 'r', encoding='utf-8') as fh:
|
||||
data = json.load(fh)
|
||||
cmd = str(data.get('commander') or '').strip() or 'Unknown Commander'
|
||||
themes = [t for t in [data.get('primary_tag'), data.get('secondary_tag'), data.get('tertiary_tag')] if isinstance(t, str) and t.strip()]
|
||||
return f"{cmd} - {', '.join(themes)}" if themes else cmd
|
||||
except Exception:
|
||||
return p
|
||||
print("\nAvailable JSON configs:")
|
||||
for idx, f in enumerate(configs, start=1):
|
||||
print(f" {idx}) {_label(f)}")
|
||||
print(" 0) Cancel")
|
||||
while True:
|
||||
try:
|
||||
sel = input("Select a config to run [0]: ").strip() or '0'
|
||||
except KeyboardInterrupt:
|
||||
print("")
|
||||
sel = '0'
|
||||
if sel == '0':
|
||||
return 0
|
||||
try:
|
||||
i = int(sel)
|
||||
if 1 <= i <= len(configs):
|
||||
chosen = configs[i - 1]
|
||||
json_cfg = _load_json_config(chosen)
|
||||
os.environ['DECK_CONFIG'] = chosen
|
||||
break
|
||||
except ValueError:
|
||||
pass
|
||||
print("Invalid selection. Try again.")
|
||||
else:
|
||||
# No explicit file; if exactly one config exists, auto use it; else leave empty
|
||||
if len(configs) == 1:
|
||||
json_cfg = _load_json_config(configs[0])
|
||||
os.environ['DECK_CONFIG'] = configs[0]
|
||||
# No explicit file; if exactly one config exists in a known dir, use it
|
||||
for candidate_dir in [cfg_path] if cfg_path and os.path.isdir(cfg_path) else ["/app/config", "config"]:
|
||||
try:
|
||||
files = [f for f in (os.listdir(candidate_dir) if os.path.isdir(candidate_dir) else []) if f.lower().endswith(".json")]
|
||||
except Exception:
|
||||
files = []
|
||||
if len(files) == 1:
|
||||
chosen = os.path.join(candidate_dir, files[0])
|
||||
json_cfg = _load_json_config(chosen)
|
||||
os.environ["DECK_CONFIG"] = chosen
|
||||
break
|
||||
|
||||
# Defaults mirror run() signature
|
||||
defaults = dict(
|
||||
command_name="Pantlaza",
|
||||
command_name="",
|
||||
add_creatures=True,
|
||||
add_non_creature_spells=True,
|
||||
add_ramp=True,
|
||||
|
@ -354,10 +289,9 @@ def _main() -> int:
|
|||
add_wipes=True,
|
||||
add_card_advantage=True,
|
||||
add_protection=True,
|
||||
use_multi_theme=True,
|
||||
primary_choice=2,
|
||||
secondary_choice=2,
|
||||
tertiary_choice=2,
|
||||
primary_choice=1,
|
||||
secondary_choice=None,
|
||||
tertiary_choice=None,
|
||||
add_lands=True,
|
||||
fetch_count=3,
|
||||
dual_count=None,
|
||||
|
@ -382,10 +316,10 @@ def _main() -> int:
|
|||
"add_wipes": _resolve_value(args.add_wipes, "DECK_ADD_WIPES", json_cfg, "add_wipes", defaults["add_wipes"]),
|
||||
"add_card_advantage": _resolve_value(args.add_card_advantage, "DECK_ADD_CARD_ADVANTAGE", json_cfg, "add_card_advantage", defaults["add_card_advantage"]),
|
||||
"add_protection": _resolve_value(args.add_protection, "DECK_ADD_PROTECTION", json_cfg, "add_protection", defaults["add_protection"]),
|
||||
"use_multi_theme": _resolve_value(args.use_multi_theme, "DECK_USE_MULTI_THEME", json_cfg, "use_multi_theme", defaults["use_multi_theme"]),
|
||||
"primary_choice": _resolve_value(args.primary_choice, "DECK_PRIMARY_CHOICE", json_cfg, "primary_choice", defaults["primary_choice"]),
|
||||
"secondary_choice": _resolve_value(args.secondary_choice, "DECK_SECONDARY_CHOICE", json_cfg, "secondary_choice", defaults["secondary_choice"]),
|
||||
"tertiary_choice": _resolve_value(args.tertiary_choice, "DECK_TERTIARY_CHOICE", json_cfg, "tertiary_choice", defaults["tertiary_choice"]),
|
||||
"bracket_level": _resolve_value(args.bracket_level, "DECK_BRACKET_LEVEL", json_cfg, "bracket_level", None),
|
||||
"add_lands": _resolve_value(args.add_lands, "DECK_ADD_LANDS", json_cfg, "add_lands", defaults["add_lands"]),
|
||||
"fetch_count": _resolve_value(args.fetch_count, "DECK_FETCH_COUNT", json_cfg, "fetch_count", defaults["fetch_count"]),
|
||||
"dual_count": _resolve_value(args.dual_count, "DECK_DUAL_COUNT", json_cfg, "dual_count", defaults["dual_count"]),
|
||||
|
@ -398,6 +332,54 @@ def _main() -> int:
|
|||
print(json.dumps(resolved, indent=2))
|
||||
return 0
|
||||
|
||||
# Optional: map tag names from JSON/env to numeric indices for this commander
|
||||
try:
|
||||
primary_tag_name = (str(os.getenv("DECK_PRIMARY_TAG") or "").strip()) or str(json_cfg.get("primary_tag", "")).strip()
|
||||
secondary_tag_name = (str(os.getenv("DECK_SECONDARY_TAG") or "").strip()) or str(json_cfg.get("secondary_tag", "")).strip()
|
||||
tertiary_tag_name = (str(os.getenv("DECK_TERTIARY_TAG") or "").strip()) or str(json_cfg.get("tertiary_tag", "")).strip()
|
||||
tag_names = [t for t in [primary_tag_name, secondary_tag_name, tertiary_tag_name] if t]
|
||||
if tag_names:
|
||||
try:
|
||||
# Load commander tags to compute indices
|
||||
tmp = DeckBuilder()
|
||||
df = tmp.load_commander_data()
|
||||
row = df[df["name"] == resolved["command_name"]]
|
||||
if not row.empty:
|
||||
original = list(dict.fromkeys(row.iloc[0].get("themeTags", []) or []))
|
||||
# Step 1: primary from original
|
||||
if primary_tag_name:
|
||||
for i, t in enumerate(original, start=1):
|
||||
if str(t).strip().lower() == primary_tag_name.strip().lower():
|
||||
resolved["primary_choice"] = i
|
||||
break
|
||||
# Step 2: secondary from remaining after primary
|
||||
if secondary_tag_name:
|
||||
primary_idx = resolved.get("primary_choice")
|
||||
remaining_1 = [t for j, t in enumerate(original, start=1) if j != primary_idx]
|
||||
for i2, t in enumerate(remaining_1, start=1):
|
||||
if str(t).strip().lower() == secondary_tag_name.strip().lower():
|
||||
resolved["secondary_choice"] = i2
|
||||
break
|
||||
# Step 3: tertiary from remaining after primary+secondary
|
||||
if tertiary_tag_name and resolved.get("secondary_choice") is not None:
|
||||
primary_idx = resolved.get("primary_choice")
|
||||
secondary_idx = resolved.get("secondary_choice")
|
||||
# reconstruct remaining after removing primary then secondary as displayed
|
||||
remaining_1 = [t for j, t in enumerate(original, start=1) if j != primary_idx]
|
||||
remaining_2 = [t for j, t in enumerate(remaining_1, start=1) if j != secondary_idx]
|
||||
for i3, t in enumerate(remaining_2, start=1):
|
||||
if str(t).strip().lower() == tertiary_tag_name.strip().lower():
|
||||
resolved["tertiary_choice"] = i3
|
||||
break
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if not str(resolved.get("command_name", "")).strip():
|
||||
print("Error: commander is required. Provide --commander or a JSON config with a 'commander' field.")
|
||||
return 2
|
||||
|
||||
run(**resolved)
|
||||
return 0
|
||||
|
||||
|
|
30
code/main.py
30
code/main.py
|
@ -35,11 +35,41 @@ def _ensure_data_ready() -> None:
|
|||
|
||||
# Ensure required CSVs exist and are tagged before proceeding
|
||||
try:
|
||||
import time
|
||||
import json as _json
|
||||
from datetime import datetime as _dt
|
||||
cards_path = os.path.join(CSV_DIRECTORY, 'cards.csv')
|
||||
flag_path = os.path.join(CSV_DIRECTORY, '.tagging_complete.json')
|
||||
refresh_needed = False
|
||||
# Missing CSV forces refresh
|
||||
if not os.path.exists(cards_path):
|
||||
logger.info("cards.csv not found. Running initial setup and tagging...")
|
||||
refresh_needed = True
|
||||
else:
|
||||
# Stale CSV (>7 days) forces refresh
|
||||
try:
|
||||
age_seconds = time.time() - os.path.getmtime(cards_path)
|
||||
if age_seconds > 7 * 24 * 60 * 60:
|
||||
logger.info("cards.csv is older than 7 days. Refreshing data (setup + tagging)...")
|
||||
refresh_needed = True
|
||||
except Exception:
|
||||
pass
|
||||
# Missing tagging flag forces refresh
|
||||
if not os.path.exists(flag_path):
|
||||
logger.info("Tagging completion flag not found. Performing full tagging...")
|
||||
refresh_needed = True
|
||||
if refresh_needed:
|
||||
initial_setup()
|
||||
tagger.run_tagging()
|
||||
# Write tagging completion flag
|
||||
try:
|
||||
os.makedirs(CSV_DIRECTORY, exist_ok=True)
|
||||
with open(flag_path, 'w', encoding='utf-8') as _fh:
|
||||
_json.dump({
|
||||
'tagged_at': _dt.now().isoformat(timespec='seconds')
|
||||
}, _fh)
|
||||
except Exception:
|
||||
logger.warning("Failed to write tagging completion flag (non-fatal).")
|
||||
logger.info("Initial setup and tagging completed.")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed ensuring CSVs are ready: {e}")
|
||||
|
|
0
code/non_interactive_test.py
Normal file
0
code/non_interactive_test.py
Normal file
|
@ -2817,7 +2817,8 @@ def tag_for_explore_and_map(df: pd.DataFrame, color: str) -> None:
|
|||
if explore_mask.any():
|
||||
rules.append({ 'mask': explore_mask, 'tags': ['Card Selection'] })
|
||||
# If the text also references +1/+1 counters, add that theme
|
||||
explore_counters = explore_mask & tag_utils.create_text_mask(df, ['+1/+1 counter'])
|
||||
# Use literal match for '+1/+1 counter' to avoid regex errors on '+' at start
|
||||
explore_counters = explore_mask & tag_utils.create_text_mask(df, ['+1/+1 counter'], regex=False)
|
||||
if explore_counters.any():
|
||||
rules.append({ 'mask': explore_counters, 'tags': ['+1/+1 Counters'] })
|
||||
if map_mask.any():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue