763e06c127
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3.3 KiB
3.3 KiB
name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
| name | kind | lang | domain | version | purity | signature | description | tags | uses_functions | uses_types | returns | returns_optional | error_type | imports | params | output | tested | tests | test_file_path | file_path | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| fetch_reddit_search | function | py | datascience | 1.0.0 | impure | def fetch_reddit_search(query: str, subreddits: list[str] = None, limit: int = 50, sort: str = "new") -> list[dict] | Busca posts en Reddit via la API JSON publica (sin auth) y los normaliza a un shape comun de market intelligence. Por subreddit (o global si None), GET a search.json con t=year. Tolera errores por subreddit (429, red) continuando con los demas. Requiere User-Agent obligatorio. |
|
false | error_go_core |
|
|
list[dict] (puede ser []). Cada fila: {source:'reddit', platform_id:str, title:str, body:str, url:str, author:str, channel:str, created_utc:float, platform_score:int, query:str} | true |
|
python/functions/datascience/fetch_reddit_search_test.py | python/functions/datascience/fetch_reddit_search.py |
Ejemplo
from datascience import fetch_reddit_search
# Buscar en subreddits concretos
rows = fetch_reddit_search(
"csv dedupe tool",
subreddits=["SaaS", "Entrepreneur"],
limit=25,
sort="new",
)
for r in rows[:3]:
print(r["channel"], r["platform_score"], r["title"])
# Busqueda global (sin subreddits)
rows_global = fetch_reddit_search("i wish there was a tool", limit=50)
Cuando usarla
Usala como primera fase de un pipeline de market intelligence: recolectar
conversaciones reales de Reddit donde la gente expresa necesidades o busca
herramientas. Combina la salida con score_demand_signal para puntuar cada
post por senal de demanda. Cubre subreddits de nicho (subreddits=[...]) o
escanea todo Reddit (busqueda global).
Gotchas
- User-Agent obligatorio: Reddit devuelve
429 Too Many Requestssi no se envia un User-Agent identificable. Esta funcion enviademand_radar/0.1 (registry market-intel)por defecto. - Rate limiting: la API publica sin auth tiene limites estrictos. Si haces muchas llamadas seguidas o pides muchos subreddits, Reddit puede empezar a devolver 429. La funcion tolera estos fallos por subreddit (try/except) y sigue con los demas — un 429 en un subreddit no aborta la busqueda completa, simplemente ese subreddit aporta 0 filas.
- Sin red = lista vacia, no excepcion: si todas las peticiones fallan,
devuelve
[]. Revisa el tamano del resultado, no asumas exito. created_utces epoch en segundos (float).platform_scoreson los upvotes netos (ups), 0 si Reddit no lo provee.t=yearfija la ventana temporal a un ano; no es parametrizable en esta version (mantiene la firma simple).