Set up tools/import-pokedb/ with CLI, JSON loader, and output models. Replaces the Go/PokeAPI approach with local PokeDB.org JSON processing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
116 lines
3.4 KiB
Python
116 lines
3.4 KiB
Python
"""CLI entry point for the PokeDB import tool.
|
|
|
|
Usage:
|
|
# From repo root:
|
|
python -m import_pokedb ./pokedb-export/
|
|
|
|
# With options:
|
|
python -m import_pokedb ./pokedb-export/ --output backend/src/app/seeds/data/ --game firered
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from .loader import load_pokedb_data, load_seed_config
|
|
|
|
SEEDS_DIR_CANDIDATES = [
|
|
Path("backend/src/app/seeds"), # from repo root
|
|
Path("../../backend/src/app/seeds"), # from tools/import-pokedb/
|
|
]
|
|
|
|
|
|
def find_seeds_dir() -> Path:
|
|
"""Locate the backend seeds directory."""
|
|
for candidate in SEEDS_DIR_CANDIDATES:
|
|
if (candidate / "version_groups.json").exists():
|
|
return candidate.resolve()
|
|
# Fallback
|
|
return Path("backend/src/app/seeds").resolve()
|
|
|
|
|
|
def build_parser() -> argparse.ArgumentParser:
|
|
parser = argparse.ArgumentParser(
|
|
prog="import-pokedb",
|
|
description="Convert PokeDB.org JSON data exports into nuzlocke-tracker seed format.",
|
|
)
|
|
parser.add_argument(
|
|
"pokedb_dir",
|
|
type=Path,
|
|
help="Path to directory containing PokeDB JSON export files",
|
|
)
|
|
parser.add_argument(
|
|
"--output",
|
|
type=Path,
|
|
default=None,
|
|
help="Output directory for seed JSON files (default: backend/src/app/seeds/data/)",
|
|
)
|
|
parser.add_argument(
|
|
"--game",
|
|
type=str,
|
|
default=None,
|
|
help="Generate data for a specific game slug only (default: all games)",
|
|
)
|
|
return parser
|
|
|
|
|
|
def main(argv: list[str] | None = None) -> None:
|
|
parser = build_parser()
|
|
args = parser.parse_args(argv)
|
|
|
|
pokedb_dir: Path = args.pokedb_dir
|
|
if not pokedb_dir.is_dir():
|
|
print(f"Error: {pokedb_dir} is not a directory", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
seeds_dir = find_seeds_dir()
|
|
output_dir: Path = args.output or (seeds_dir / "data")
|
|
output_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
print(f"PokeDB data: {pokedb_dir.resolve()}")
|
|
print(f"Seeds config: {seeds_dir}")
|
|
print(f"Output: {output_dir.resolve()}")
|
|
print()
|
|
|
|
# Load PokeDB export data
|
|
pokedb = load_pokedb_data(pokedb_dir)
|
|
print(pokedb.summary())
|
|
print()
|
|
|
|
# Load existing seed configuration
|
|
config = load_seed_config(seeds_dir)
|
|
print(f"Loaded {len(config.version_groups)} version groups")
|
|
print(f"Loaded route order for {len(config.route_order)} version groups")
|
|
if config.special_encounters:
|
|
se_count = len(config.special_encounters.get("encounters", {}))
|
|
print(f"Loaded special encounters for {se_count} version groups")
|
|
print()
|
|
|
|
# Determine which games to process
|
|
target_game = args.game
|
|
if target_game:
|
|
found = False
|
|
for vg_info in config.version_groups.values():
|
|
if target_game in vg_info.get("versions", []):
|
|
found = True
|
|
break
|
|
if not found:
|
|
print(f"Error: Game '{target_game}' not found in version_groups.json", file=sys.stderr)
|
|
sys.exit(1)
|
|
print(f"Target: {target_game}")
|
|
else:
|
|
total_games = sum(
|
|
len(vg.get("versions", []))
|
|
for vg in config.version_groups.values()
|
|
)
|
|
print(f"Target: all {total_games} games")
|
|
|
|
# TODO: Processing pipeline (subtasks zno2, rfg0, gkcy)
|
|
print("\nScaffold loaded successfully. Processing pipeline not yet implemented.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|