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
1.7 KiB
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— Addedepisode_number: int | NonetoShowdataclass.src/ntr_fetcher/db.py— Addedepisode_numbercolumn to schema, ALTER TABLE migration for existing DBs, updatedget_or_create_showto accept/store episode numbers, addedget_latest_episode_number()andupdate_show_episode_number(), changedlist_showsordering toweek_start DESC.src/ntr_fetcher/main.py— Addedargparsewith--init,--show,--airedflags.--initruns 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— Addedepisode_numberto/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, andget_latest_episode_number.tests/test_poller.py— Auto-numbering when history exists, skips when no history, skips when already assigned.tests/test_api.py—episode_numberpresent 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