Recipes

News Aggregator

Aggregate headlines from multiple news sources with two batch passes

Two-pass design: distill each source's homepage to discover article URLs, then extract structured headline records from those URLs.

Flow

  1. Pass 1/batch/distill on each source's homepage with include: ["links"]
  2. Filter discovered links by pattern (e.g. today's date, article paths)
  3. Pass 2/batch/extract on the filtered URLs with a headline schema
  4. Webhook fires when both passes complete; ingest into your store

Schema

{
  "type": "object",
  "properties": {
    "title":       { "type": "string", "description": "The article headline" },
    "url":         { "type": "string", "description": "Canonical article URL" },
    "publishedAt": { "type": "string", "description": "ISO-8601 publish timestamp" },
    "summary":     { "type": "string", "description": "1-2 sentence summary" }
  },
  "required": ["title", "url"]
}

Implementation sketch

import httpx

API = "https://openapi.thunderbit.com/openapi/v1"
H = {"Authorization": "Bearer YOUR_API_KEY"}

# Pass 1: distill homepages, collect article URLs
sources = ["https://news.example.com", "https://blog.example.org"]
home_job = httpx.post(f"{API}/batch/distill",
                      headers=H,
                      json={"urls": sources, "include": ["links"]}).json()
# (poll until COMPLETED — see Batch Job Lifecycle guide)

article_urls = []
for r in home_job["data"]["results"]:
    if r["status"] == "SUCCEEDED":
        article_urls += [u for u in r["links"] if "/article/" in u]

# Pass 2: extract structured headlines
extract_job = httpx.post(f"{API}/batch/extract",
                         headers=H,
                         json={"urls": article_urls, "schema": SCHEMA}).json()

Tips

  • Cache homepage results (5-10 min TTL) to avoid burning credits on the same headlines
  • Set a countryCode if a source localizes its homepage by IP
  • Dedupe by canonical URL or content hash — the same headline often appears on multiple sources

This recipe is being expanded with a complete two-pass orchestrator — check back soon.