Puede monitorear Reddit en busca de menciones de marca buscando con la plataforma configurada para reddit en la API de búsqueda de Scavio, filtrando nuevas publicaciones desde la última ejecución y publicando alertas en Slack cuando se encuentren menciones.
Requisitos previos
- Python 3.9+
- Clave API de Scavio
- URL de webhook de Slack (opcional)
Guia paso a paso
Paso 1: Busque en Reddit menciones de marca
Configure plataforma:reddit para restringir los resultados a publicaciones y comentarios de Reddit.
import requests
API_KEY = "your-scavio-api-key"
def search_reddit(brand: str, num_results: int = 20) -> list:
r = requests.post(
"https://api.scavio.dev/api/v1/search",
json={"query": brand, "platform": "reddit", "num_results": num_results},
headers={"x-api-key": API_KEY},
timeout=15
)
r.raise_for_status()
return r.json().get("organic_results", [])
mentions = search_reddit("YourBrand")
for m in mentions:
print(m.get("title"), m.get("link"))Paso 2: Deduplicar con SQLite
Almacene las URL vistas para recibir alertas solo sobre nuevas menciones.
import sqlite3
def init_db(path="reddit_mentions.db"):
conn = sqlite3.connect(path)
conn.execute("""
CREATE TABLE IF NOT EXISTS seen (
url TEXT PRIMARY KEY,
title TEXT,
first_seen TEXT
)
""")
conn.commit()
return conn
def filter_new(conn, mentions: list) -> list:
from datetime import date
new = []
for m in mentions:
url = m.get("link", "")
exists = conn.execute("SELECT 1 FROM seen WHERE url=?", (url,)).fetchone()
if not exists:
conn.execute("INSERT INTO seen VALUES (?, ?, ?)",
(url, m.get("title"), str(date.today())))
new.append(m)
conn.commit()
return newPaso 3: Enviar alerta de Slack para nuevas menciones
Publique cada nueva mención como un mensaje de Slack a través de un webhook.
import json
def send_slack_alert(webhook_url: str, brand: str, mention: dict):
message = {
"text": f"*New Reddit mention of {brand}*",
"blocks": [
{"type": "section", "text": {"type": "mrkdwn",
"text": f"*<{mention['link']}|{mention['title'][:100]}>*"}},
{"type": "section", "text": {"type": "mrkdwn",
"text": mention.get("snippet", "")[:300]}}
]
}
requests.post(webhook_url, json=message, timeout=10)Paso 4: Ejecutar como un cron diario
Guarde como reddit_monitor.py y programe: 0 8 * * * python /path/to/reddit_monitor.py
BRAND = "YourBrand"
SLACK_WEBHOOK = "https://hooks.slack.com/services/xxx/yyy/zzz" # or None
conn = init_db()
mentions = search_reddit(BRAND, num_results=20)
new_mentions = filter_new(conn, mentions)
print(f"Found {len(new_mentions)} new mentions of '{BRAND}'")
for m in new_mentions:
print(f" {m['title'][:80]}")
print(f" {m['link']}")
if SLACK_WEBHOOK:
send_slack_alert(SLACK_WEBHOOK, BRAND, m)Ejemplo en Python
import requests
import sqlite3
from datetime import date
API_KEY = "your-scavio-api-key"
BRAND = "YourBrand"
SLACK_WEBHOOK = None # Set to your Slack webhook URL
def search_reddit(brand, n=20):
r = requests.post("https://api.scavio.dev/api/v1/search",
json={"query": brand, "platform": "reddit", "num_results": n},
headers={"x-api-key": API_KEY}, timeout=15)
r.raise_for_status()
return r.json().get("organic_results", [])
def init_db(path="reddit_mentions.db"):
conn = sqlite3.connect(path)
conn.execute("CREATE TABLE IF NOT EXISTS seen (url TEXT PRIMARY KEY, title TEXT, first_seen TEXT)")
conn.commit()
return conn
def get_new(conn, mentions):
new = []
for m in mentions:
url = m.get("link","")
if not conn.execute("SELECT 1 FROM seen WHERE url=?", (url,)).fetchone():
conn.execute("INSERT INTO seen VALUES (?,?,?)", (url, m.get("title"), str(date.today())))
new.append(m)
conn.commit()
return new
def alert(webhook, brand, m):
if not webhook: return
requests.post(webhook, json={"text": f"New Reddit mention of {brand}: <{m['link']}|{m['title'][:100]}>"}, timeout=10)
if __name__ == "__main__":
conn = init_db()
mentions = search_reddit(BRAND)
new = get_new(conn, mentions)
print(f"[{date.today()}] {BRAND}: {len(new)} new mentions (of {len(mentions)} total)")
for m in new:
print(f" r/{m.get('source_subreddit','?')} | {m['title'][:70]}")
print(f" {m['link']}")
alert(SLACK_WEBHOOK, BRAND, m)Ejemplo en JavaScript
const API_KEY = 'your-scavio-api-key';
async function searchReddit(brand, n = 20) {
const res = await fetch('https://api.scavio.dev/api/v1/search', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'x-api-key': API_KEY },
body: JSON.stringify({ query: brand, platform: 'reddit', num_results: n })
});
const data = await res.json();
return data.organic_results ?? [];
}
const mentions = await searchReddit('YourBrand');
for (const m of mentions.slice(0, 5)) {
console.log(`${m.title?.slice(0, 80)}`);
console.log(` ${m.link}`);
}Salida esperada
[2026-05-22] YourBrand: 3 new mentions (of 18 total)
r/SaaS | Has anyone tried YourBrand for team project management?
https://reddit.com/r/SaaS/comments/abc123/
r/entrepreneur | YourBrand vs Notion - which is better for solo founders?
https://reddit.com/r/entrepreneur/comments/def456/
r/productivity | YourBrand just launched a new AI feature
https://reddit.com/r/productivity/comments/ghi789/