feat(ingestion): add first public LBA Serie A importer

This commit is contained in:
bisco
2026-04-11 00:45:33 +02:00
parent 9524c928e2
commit 88ca5cde10
5 changed files with 702 additions and 1 deletions

View File

@ -0,0 +1,57 @@
from __future__ import annotations
from pathlib import Path
from django.core.management.base import BaseCommand, CommandError
from scouting.importers.lba_public import (
LBA_SOURCE_NAME,
LbaFixtureStatsSource,
LbaPublicStatsSource,
LbaSerieAPublicImporter,
ImportValidationError,
)
class Command(BaseCommand):
help = "Import public LBA Serie A player statistics for one season using the ADR-0009 baseline flow."
def add_arguments(self, parser):
parser.add_argument(
"--season",
type=int,
default=2025,
help="Season start year to import from LBA public statistics API (default: 2025).",
)
parser.add_argument(
"--fixture",
default="",
help="Optional local fixture JSON path for deterministic/offline runs.",
)
def handle(self, *args, **options):
season_start_year = options["season"]
fixture_path = (options.get("fixture") or "").strip()
try:
if fixture_path:
source = LbaFixtureStatsSource(Path(fixture_path))
source_label = f"fixture={fixture_path}"
else:
source = LbaPublicStatsSource()
source_label = "public=https://www.legabasket.it/api/statistics/get-players-statistics"
summary = LbaSerieAPublicImporter(season_start_year=season_start_year, source=source).run()
except ImportValidationError as exc:
raise CommandError(f"LBA public import failed: {exc}") from exc
self.stdout.write(
self.style.SUCCESS(
"Imported LBA Serie A public statistics successfully. "
f"Source={LBA_SOURCE_NAME}; season={season_start_year}; "
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"Input: {source_label}")