Recepten

Nieuwsaggregator

Aggregeer headlines uit meerdere nieuwsbronnen met twee batch-passes

Two-pass-ontwerp: distill de homepage van elke bron om artikel-URLs te ontdekken, en extract dan gestructureerde headline-records uit die URLs.

Flow

  1. Pass 1/batch/distill op de homepage van elke bron met include: ["links"]
  2. Filter ontdekte links op patroon (bv. de datum van vandaag, artikelpaden)
  3. Pass 2/batch/extract op de gefilterde URLs met een headline-schema
  4. Webhook gaat af wanneer beide passes voltooid zijn; ingest naar je 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"]
}

Implementatieschets

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-resultaten (5-10 min TTL) om te voorkomen dat je credits verbrandt op dezelfde headlines
  • Stel een countryCode in als een bron zijn homepage lokaliseert op IP
  • Dedupliceer op canonieke URL of content-hash — dezelfde headline verschijnt vaak op meerdere bronnen

Gerelateerd

Dit recept wordt uitgebreid met een complete two-pass-orchestrator — kom binnenkort terug.