Download one hoopR table for a range of seasons.
Files already present and readable are skipped unless --force is given, so
re-running after an interruption costs only the seasons that are missing.
Source code in src/pippen/cli.py
| @app.command()
def fetch(
seasons: Annotated[
str,
typer.Option(help="A season, 2024, or an inclusive range, 2015-2024."),
],
dataset: Annotated[
str,
typer.Option(help="Which hoopR table to download."),
] = "play_by_play",
force: Annotated[
bool,
typer.Option(help="Re-download even when a valid file is already present."),
] = False,
) -> None:
"""Download one hoopR table for a range of seasons.
Files already present and readable are skipped unless --force is given, so
re-running after an interruption costs only the seasons that are missing.
"""
wanted = _parse_seasons(seasons)
if dataset not in hoopr.DATASETS:
known = ", ".join(sorted(hoopr.DATASETS))
console.print(f"[red]unknown dataset[/red] {dataset!r}. Known datasets: {known}")
raise typer.Exit(code=2)
if hoopr.is_master_dataset(dataset):
# Published as one file covering every season, so the requested range
# selects nothing. Downloading it once per season would store the same
# file repeatedly.
console.print(f"{dataset} is published as one file covering every season")
results = [hoopr.download_master(dataset, force=force)]
console.print(f"{results[0].status} {dataset}")
else:
results = hoopr.download_seasons(dataset, wanted, force=force, console=console)
failed = [r for r in results if r.status == "failed"]
downloaded = sum(1 for r in results if r.status == "downloaded")
skipped = sum(1 for r in results if r.status == "skipped")
console.print(
f"\n{len(results)} season(s): {downloaded} downloaded, "
f"{skipped} already present, {len(failed)} failed"
)
if failed:
raise typer.Exit(code=1)
|