レシピ

ニュースアグリゲーター

2 段階のバッチ処理で複数のニュースソースから見出しを集約する

2 段階設計:各ソースのホームページを Distill して記事 URL を発見し、それらの URL から構造化された見出しレコードを Extract します。

フロー

  1. Pass 1 —— 各ソースのホームページに対して include: ["links"] 付きで /batch/distill
  2. 発見されたリンクをパターン(例:本日の日付、記事パス)でフィルタリング
  3. Pass 2 —— フィルタ後の URL に対して見出しスキーマで /batch/extract
  4. 両方のパスが完了した時点で Webhook が発火 —— ストアに取り込み

スキーマ

{
  "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"]
}

実装スケッチ

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()

ヒント

  • ホームページの結果をキャッシュ(5〜10 分の TTL)して、同じ見出しでクレジットを浪費しないようにしましょう
  • ソースが IP によってホームページをローカライズする場合は countryCode を設定しましょう
  • 正規 URL またはコンテンツハッシュで重複排除しましょう —— 同じ見出しが複数のソースに現れることがよくあります

関連

このレシピは現在 2 段階オーケストレーターの完全なサンプルを追加して拡張中です —— 近日中にご確認ください。