Move the grid download loop into an importable scrape package - #20
Merged
Merged
Conversation
scrape.Fetch(ctx, prefs, opts) downloads every six-hour slot for a lineup and assembles a guide.TVGuide: stations deduplicated in first-seen order, every lineup position retained, programs deduplicated. It does no enrichment, file I/O, or environment reads. main.runScrape now calls it, mapping progress to the setup status and cancelling the context when the active lineup changes mid-download. Behavior change: when every slot fails, the scrape is now an error (scrape.ErrNoData) instead of writing an empty guide, so the previous guide stays live and the 15-minute retry applies. Channel order in the XMLTV output is now first-seen rather than map order.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR 4 of #15. Stacked on #19.
Changes
scrapepackage withFetch(ctx, prefs, opts) (*guide.TVGuide, error). It downloads every six-hour slot for a lineup and assembles the guide:Channelsdeduplicated by station in first-seen order,Lineupwith every position,Programsdeduplicated by station and time, andSource. No enrichment, no file I/O, no env reads.Optionscovers days, inter-slot delay, an injectableGridFetcher(which*web.Clientsatisfies), a clock, a per-slotProgresscallback, and a logger. The zero value is production configuration.main.runScrapecallsscrape.Fetch, maps progress onto the setup status page, and cancels the context when the active lineup changes mid-download (polled once per second, with a live re-check after the fetch).Behavior changes to be aware of
scrape.ErrNoDatainstead of writing an empty guide. The previous guide stays live and the existing 15-minute retry applies.Tests
scrape: slot alignment and count; full assembly with a station at two numbers; distinct events across slots kept while repeats are deduplicated; a failed slot skipped and reported with progress counts monotonic;ErrNoDatawhen all fail; cancellation during the delay, during a request, and before the first request; option defaults. Runs clean under-race.main:runScrapeend to end with a fake fetcher (lineup assembled, proxy rewrite applied, files written, progress stages reported); a lineup change is reported aserrScrapeSourceChangedand the persister never runs; total failure surfacesErrNoDataand the persister never runs.