Files
NtR-soudcloud-fetcher/chat-summaries/2026-03-12_16-30-summary.md
cottongin cb3ae403cf feat: add historical backfill with --init CLI and episode numbering
Adds a --init mode that seeds the database with past shows from a given
anchor episode/date forward, batch-fetching likes from SoundCloud and
partitioning them into weekly buckets. Episode numbers are tracked in
the shows table and auto-incremented by the poller for new shows.

Includes full API documentation (docs/api.md) and updated README.

Made-with: Cursor
2026-03-12 02:09:15 -04:00

1.7 KiB

Historical Backfill (--init) Feature

Task

Add CLI-based historical show backfill with episode numbering throughout the system.

Changes Made

New file

  • src/ntr_fetcher/backfill.py — Computes show weeks from an anchor episode/date, batch-fetches all likes from SoundCloud, partitions them into weekly buckets, and populates the DB.

Modified files

  • src/ntr_fetcher/models.py — Added episode_number: int | None to Show dataclass.
  • src/ntr_fetcher/db.py — Added episode_number column to schema, ALTER TABLE migration for existing DBs, updated get_or_create_show to accept/store episode numbers, added get_latest_episode_number() and update_show_episode_number(), changed list_shows ordering to week_start DESC.
  • src/ntr_fetcher/main.py — Added argparse with --init, --show, --aired flags. --init runs backfill then exits; default starts the server as before.
  • src/ntr_fetcher/poller.py — Auto-assigns episode number (latest + 1) when creating a new show if historical data exists.
  • src/ntr_fetcher/api.py — Added episode_number to /playlist, /shows, /shows/{show_id} responses.

New/updated tests

  • tests/test_backfill.py — Week computation, batch partitioning, empty data, idempotency.
  • tests/test_db.py — Episode number creation, update, and get_latest_episode_number.
  • tests/test_poller.py — Auto-numbering when history exists, skips when no history, skips when already assigned.
  • tests/test_api.pyepisode_number present in show responses.

Results

  • 58 tests passing (up from 42), ruff clean.

Usage

NTR_ADMIN_TOKEN=token ntr-fetcher --init --show 521 --aired 2026-01-07