Un agregador de noticias que combina artículos de Google News, debates de Reddit y vídeos de YouTube sobre cualquier tema ofrece una imagen más completa que cualquier fuente única. Google News proporciona cobertura editorial, Reddit muestra las reacciones de la comunidad y YouTube captura comentarios en vídeo. Este tutorial crea un agregador de fuentes múltiples utilizando la API de Scavio que consulta las tres plataformas, normaliza los resultados en un formato común, deduplica por URL y clasifica según una puntuación de relevancia combinada.
Requisitos previos
- Python 3.10 o superior
- solicita biblioteca instalada
- Una clave API de Scavio
- Temas o palabras clave para agregar noticias
Guia paso a paso
Paso 1: Consulta las tres fuentes
Obtenga resultados de Google News, publicaciones de Reddit y videos de YouTube sobre el mismo tema utilizando la API de Scavio.
from concurrent.futures import ThreadPoolExecutor
def fetch_google_news(topic: str) -> list[dict]:
r = requests.post(ENDPOINT, headers={"x-api-key": API_KEY},
json={"query": f"{topic} news", "country_code": "us"})
r.raise_for_status()
return r.json().get("news_results", r.json().get("organic_results", []))
def fetch_reddit(topic: str) -> list[dict]:
r = requests.post(ENDPOINT, headers={"x-api-key": API_KEY},
json={"platform": "reddit", "query": topic})
r.raise_for_status()
return r.json().get("data", {}).get("posts", [])
def fetch_youtube(topic: str) -> list[dict]:
r = requests.post(ENDPOINT, headers={"x-api-key": API_KEY},
json={"platform": "youtube", "query": topic})
r.raise_for_status()
return r.json().get("videos", [])Paso 2: Normalizar resultados en un formato común
Transforme los resultados de cada plataforma en una estructura uniforme con título, URL, fuente y fragmento.
def normalize_google(item: dict) -> dict:
return {"title": item.get("title"), "url": item.get("link"), "source": "google", "snippet": item.get("snippet", ""), "date": item.get("date")}
def normalize_reddit(post: dict) -> dict:
return {"title": post.get("title"), "url": post.get("url"), "source": "reddit", "snippet": f"r/{post.get('subreddit', '')}", "date": post.get("timestamp")}
def normalize_youtube(video: dict) -> dict:
return {"title": video.get("title"), "url": video.get("url"), "source": "youtube", "snippet": video.get("description", "")[:100], "date": video.get("published_at")}Paso 3: Deduplicar por URL
Elimine las entradas duplicadas que aparecen en las fuentes utilizando la URL como clave de deduplicación.
def deduplicate(items: list[dict]) -> list[dict]:
seen = {}
for item in items:
url = item.get("url", "")
if url and url not in seen:
seen[url] = item
return list(seen.values())Paso 4: Generar el feed agregado
Imprima el feed combinado y deduplicado agrupado por fuente para facilitar su consumo.
def aggregate(topic: str) -> list[dict]:
with ThreadPoolExecutor(max_workers=3) as ex:
g = ex.submit(fetch_google_news, topic)
r = ex.submit(fetch_reddit, topic)
y = ex.submit(fetch_youtube, topic)
items = [normalize_google(i) for i in g.result()[:5]]
items += [normalize_reddit(i) for i in r.result()[:5]]
items += [normalize_youtube(i) for i in y.result()[:5]]
return deduplicate(items)Ejemplo en Python
import os
import requests
from concurrent.futures import ThreadPoolExecutor
API_KEY = os.environ.get("SCAVIO_API_KEY", "your_scavio_api_key")
ENDPOINT = "https://api.scavio.dev/api/v1/search"
def fetch(body: dict) -> dict:
r = requests.post(ENDPOINT, headers={"x-api-key": API_KEY}, json=body)
r.raise_for_status()
return r.json()
def aggregate(topic: str) -> list[dict]:
with ThreadPoolExecutor(max_workers=3) as ex:
g = ex.submit(fetch, {"query": f"{topic} news", "country_code": "us"})
r = ex.submit(fetch, {"platform": "reddit", "query": topic})
y = ex.submit(fetch, {"platform": "youtube", "query": topic})
items = []
for i in (g.result().get("news_results") or g.result().get("organic_results", []))[:5]:
items.append({"src": "google", "title": i.get("title"), "url": i.get("link")})
for p in r.result().get("data", {}).get("posts", [])[:5]:
items.append({"src": "reddit", "title": p.get("title"), "url": p.get("url")})
for v in y.result().get("videos", [])[:5]:
items.append({"src": "youtube", "title": v.get("title"), "url": v.get("url")})
return items
if __name__ == "__main__":
for item in aggregate("AI agents 2026"):
print(f"[{item['src']:>7}] {item['title'][:60]}")Ejemplo en JavaScript
const API_KEY = process.env.SCAVIO_API_KEY || "your_scavio_api_key";
const ENDPOINT = "https://api.scavio.dev/api/v1/search";
async function call(body) {
const res = await fetch(ENDPOINT, {
method: "POST",
headers: { "x-api-key": API_KEY, "Content-Type": "application/json" },
body: JSON.stringify(body)
});
return res.json();
}
async function aggregate(topic) {
const [g, r, y] = await Promise.all([
call({ query: `${topic} news`, country_code: "us" }),
call({ platform: "reddit", query: topic }),
call({ platform: "youtube", query: topic })
]);
const items = [];
(g.news_results || g.organic_results || []).slice(0, 5).forEach(i => items.push({ src: "google", title: i.title }));
(r.data?.posts || []).slice(0, 5).forEach(p => items.push({ src: "reddit", title: p.title }));
(y.videos || []).slice(0, 5).forEach(v => items.push({ src: "youtube", title: v.title }));
return items;
}
aggregate("AI agents 2026").then(items => items.forEach(i => console.log(`[${i.src}] ${i.title}`))).catch(console.error);Salida esperada
[ google] OpenAI Launches Agent Building Platform for Enterprise
[ google] Anthropic Expands Claude Agent Capabilities
[ reddit] Has anyone deployed AI agents in production yet?
[ reddit] Best frameworks for building AI agents in 2026
[youtube] I Built an AI Agent That Runs My Business
[youtube] AI Agents Explained - Complete 2026 Guide