trying to get sub label showed properly
This commit is contained in:
@@ -29,6 +29,8 @@ def import_group() -> None:
|
||||
help="Only import activities after this date (default: incremental from last sync).")
|
||||
@click.option("--reauth", is_flag=True, default=False,
|
||||
help="Force re-authorization even if valid tokens exist.")
|
||||
@click.option("--dev", "dev_sample", default=None, type=int, metavar="N",
|
||||
help="Dev mode: import only the N most recent activities, output to /tmp/bincio_dev/.")
|
||||
def strava_cmd(
|
||||
client_id: Optional[str],
|
||||
client_secret: Optional[str],
|
||||
@@ -36,6 +38,7 @@ def strava_cmd(
|
||||
config_path: Optional[str],
|
||||
since: Optional[str],
|
||||
reauth: bool,
|
||||
dev_sample: Optional[int],
|
||||
) -> None:
|
||||
"""Import activities from Strava.
|
||||
|
||||
@@ -90,7 +93,11 @@ def strava_cmd(
|
||||
"Add them to extract_config.yaml under import.strava, or pass --client-id/--client-secret."
|
||||
)
|
||||
|
||||
out = _resolve_output(output_dir, cfg)
|
||||
if dev_sample is not None:
|
||||
out = Path("/tmp/bincio_dev")
|
||||
console.print(f"[yellow]Dev mode:[/yellow] importing {dev_sample} activities → [cyan]{out}[/cyan]")
|
||||
else:
|
||||
out = _resolve_output(output_dir, cfg)
|
||||
console.print(f"Output dir: [cyan]{out}[/cyan]")
|
||||
|
||||
if reauth and TOKENS_FILE.exists():
|
||||
@@ -108,7 +115,7 @@ def strava_cmd(
|
||||
except ValueError:
|
||||
raise click.BadParameter(f"Expected YYYY-MM-DD, got {since!r}", param_hint="--since")
|
||||
|
||||
strava_sync(client, out, since_dt, console)
|
||||
strava_sync(client, out, since_dt, console, limit=dev_sample)
|
||||
|
||||
|
||||
def _load_config(config_path: Optional[str]):
|
||||
|
||||
@@ -26,7 +26,7 @@ from rich.console import Console
|
||||
from rich.progress import BarColumn, MofNCompleteColumn, Progress, TextColumn, TimeElapsedColumn
|
||||
|
||||
from bincio.extract.models import DataPoint, ParsedActivity
|
||||
from bincio.extract.sport import normalise_sport
|
||||
from bincio.extract.sport import normalise_sport, normalise_sub_sport
|
||||
|
||||
STRAVA_AUTH_URL = "https://www.strava.com/oauth/authorize"
|
||||
STRAVA_TOKEN_URL = "https://www.strava.com/oauth/token"
|
||||
@@ -214,7 +214,9 @@ def _strava_to_parsed(act: dict, streams: dict[str, list]) -> ParsedActivity:
|
||||
"""Build a ParsedActivity from a Strava activity dict + its streams."""
|
||||
started_at = datetime.fromisoformat(act["start_date"].replace("Z", "+00:00"))
|
||||
|
||||
sport = normalise_sport(act.get("sport_type") or act.get("type") or "")
|
||||
raw_sport = act.get("sport_type") or act.get("type") or ""
|
||||
sport = normalise_sport(raw_sport)
|
||||
sub_sport = normalise_sub_sport(raw_sport)
|
||||
|
||||
times = streams.get("time", []) # seconds since start
|
||||
latlngs = streams.get("latlng", []) # [[lat, lon], ...]
|
||||
@@ -244,6 +246,7 @@ def _strava_to_parsed(act: dict, streams: dict[str, list]) -> ParsedActivity:
|
||||
return ParsedActivity(
|
||||
points = points,
|
||||
sport = sport,
|
||||
sub_sport = sub_sport,
|
||||
started_at = started_at,
|
||||
source_file = f"strava_{strava_id}",
|
||||
source_hash = source_hash,
|
||||
@@ -287,6 +290,7 @@ def sync(
|
||||
output_dir: Path,
|
||||
since: datetime | None,
|
||||
console: Console,
|
||||
limit: int | None = None,
|
||||
) -> None:
|
||||
"""Fetch new Strava activities and write BAS JSON files.
|
||||
|
||||
@@ -323,6 +327,9 @@ def sync(
|
||||
f"Found [bold]{len(new_acts)}[/bold] new activities "
|
||||
f"([bold]{len(all_acts) - len(new_acts)}[/bold] already imported)."
|
||||
)
|
||||
if limit is not None and len(new_acts) > limit:
|
||||
new_acts = new_acts[:limit]
|
||||
console.print(f"[yellow]Dev mode:[/yellow] capped to {limit} activities.")
|
||||
if not new_acts:
|
||||
console.print("[green]All up to date.[/green]")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user