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
- Pass 1 —
/batch/distillon each source's homepage withinclude: ["links"] - Filter discovered links by pattern (e.g. today's date, article paths)
- Pass 2 —
/batch/extracton the filtered URLs with a headline schema - 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
countryCodeif a source localizes its homepage by IP - Dedupe by canonical URL or content hash — the same headline often appears on multiple sources
Related
This recipe is being expanded with a complete two-pass orchestrator — check back soon.