53 lines
1.8 KiB
Python
53 lines
1.8 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from django.conf import settings
|
|
from django.core.management.base import BaseCommand, CommandError
|
|
|
|
from scouting.importers.hoopdata_demo import (
|
|
HoopDataDemoCompetitionImporter,
|
|
ImportValidationError,
|
|
)
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = "Import the first real-data MVP snapshot for the hoopdata_demo source (single competition scope)."
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument(
|
|
"--input",
|
|
default=str(
|
|
Path(settings.BASE_DIR)
|
|
/ "scouting"
|
|
/ "sample_data"
|
|
/ "imports"
|
|
/ "hoopdata_demo_serie_a2_2025_2026.json"
|
|
),
|
|
help="Path to a hoopdata_demo competition snapshot JSON file.",
|
|
)
|
|
|
|
def handle(self, *args, **options):
|
|
input_path = Path(options["input"])
|
|
if not input_path.exists():
|
|
raise CommandError(f"Input file does not exist: {input_path}")
|
|
|
|
try:
|
|
payload = json.loads(input_path.read_text(encoding="utf-8"))
|
|
summary = HoopDataDemoCompetitionImporter(payload).run()
|
|
except json.JSONDecodeError as exc:
|
|
raise CommandError(f"Invalid JSON payload: {exc}") from exc
|
|
except ImportValidationError as exc:
|
|
raise CommandError(f"Import validation failed: {exc}") from exc
|
|
|
|
self.stdout.write(
|
|
self.style.SUCCESS(
|
|
"Imported hoopdata_demo competition snapshot successfully. "
|
|
f"Players +{summary.players_created}/~{summary.players_updated}, "
|
|
f"Teams +{summary.teams_created}/~{summary.teams_updated}, "
|
|
f"Contexts +{summary.contexts_created}/~{summary.contexts_updated}."
|
|
)
|
|
)
|
|
self.stdout.write(f"Source file: {input_path}")
|