Skip to main content

Architecture

newsworker is a thin CLI layer (core.py) over a service layer (service.py). The service picks an extraction strategy per page; the modules below own one concern each.

ModuleRole
service.pyFeedService: caching, strategy order, pagination, enrichment, batch
fetch.pyOutbound policy: address checks at connect time, redirects, credentials, size limits, per-host pacing (HostScheduler)
runtime.pyRequest-scoped ExtractionContext and single-flight coalescing
extractor.pyDynamic date-driven extraction (date clusters → item blocks)
dates.py / relative.pyqddate matches → plausible UTC instants; relative dates in 8 languages
structured.pyJSON-LD and microdata article lists
native.pyRSS, Atom and JSON Feed responses normalised to the item contract
undated.pyOpt-in undated listing fallback
spec/model.pyThe YAML spec (FeedSpec, FieldRule, ItemsRule) and its validation
spec/selectors.pyBuilding CSS/XPath selectors from elements and evaluating them
spec/analyze.pySpecAnalyzer: page → spec, using the dynamic heuristics once
spec/execute.pySpecExtractor: spec → items with deterministic selectors
cache.pySHA-1-keyed file caches for specs and page content
finder.pyDiscovers existing feeds via autodiscovery, icons and sitemaps
formats.pyRenders the feed dict to json/rss/atom/csv/jsonfeed/html/markdown/yaml/opml
server.pyStdlib HTTP server: /feed (tokens or signed links), health, metrics
watching.pyOne watch poll: drain due deliveries, fetch, enqueue and deliver
dedup.py / delivery.pySQLite outbox with claim tokens and item history; stdout, webhook, SMTP, Telegram, Slack, Discord, Matrix and Mastodon channels
explain.py / diagnostics.py / evaluation.pyExplaining results, strategy diagnostics, corpus scoring
jsrender.pyOptional Playwright rendering
async_fetch.pyOptional aiohttp transport for batch --async, under the same fetch policy and cache
model.pyFeed / Item typed shapes shared by every strategy and output
settings.py / settings_doc.pyLayered settings: defaults < YAML < environment < CLI; one-line docs that generate the settings reference
language.pyEvidence-based language support matrix (newsworker languages)
mcp_server.pyModel Context Protocol tools
plugins.py / bridges.pyThird-party extractors and host/path YAML overrides

Strategy order in FeedService.get_feed(): native feed (when the response is RSS/Atom/JSON Feed and no explicit spec is given) → plugin → bridge → cached or freshly analysed spec (re-analysed once if it matches nothing; skipped and not cached when it has no title or link rule) → dynamic extraction → JSON-LD/microdata when no items were found → undated fallback (opt-in) → browser rendering (opt-in). Links are then sanitised and item identities assigned from links before formatting.

The internal feed dict is the API contract between extraction and output. Its shape is declared in model.py as Feed and Item (TypedDicts, so plain dicts still work): {title, language, link, description, items: [{title, description, pubdate, unique_id, content_hash, link, extra: {links, images}, …}], provenance}. tests/test_model.py fails when a strategy emits a key the model does not declare. mypy checks the whole package.

See how it works and parsing specs.