Resumen
Developers alt-tab to navegadores 50+ times diario to look up API docs, error mensajes, y package versiones. Este flujo de trabajo agrega un shell pipeline ese searches via Scavio, caches resultados locally, y enriquece con related consultas. Subsequent lookups for el same topic hit el local cache. Cada fresh consulta costs $0.005.
Desencadenador
On-demand de terminal via shell alias o function.
Programación
On-demand de terminal
Pasos del flujo de trabajo
Verificar Local Cache for Reciente Resultados
Before making un llamada un API, verificar el local cache file for resultados de el same consulta dentro de el last 24 horas.
Ejecutar Search if Cache Miss
Si no cached resultados exist, consulta Scavio for el search term. Return structured resultados to stdout.
Cache Resultados Locally
Escribir resultados de busqueda to un local JSON cache file con un marca de tiempo. Future consultas for el same term skip el llamada un API.
Enriquecer con Related Consultas
Optionally ejecutar related searches (e.g., consulta + 'changelog', consulta + 'migration guia') y cache esos demasiado.
Implementacion en Python
#!/usr/bin/env python3
import requests, os, json, sys, hashlib
from pathlib import Path
from datetime import datetime, timedelta
API_KEY = os.environ["SCAVIO_API_KEY"]
CACHE_DIR = Path.home() / ".search_cache"
CACHE_DIR.mkdir(exist_ok=True)
CACHE_TTL = timedelta(hours=24)
def cache_key(query: str) -> str:
return hashlib.md5(query.encode()).hexdigest()
def search_with_cache(query: str) -> dict:
key = cache_key(query)
cache_file = CACHE_DIR / f"{key}.json"
if cache_file.exists():
cached = json.loads(cache_file.read_text())
if datetime.fromisoformat(cached["timestamp"]) > datetime.now() - CACHE_TTL:
return cached["data"]
resp = requests.post(
"https://api.scavio.dev/api/v1/search",
headers={"x-api-key": API_KEY, "Content-Type": "application/json"},
json={"query": query, "country_code": "us"},
timeout=10,
)
data = resp.json()
cache_file.write_text(json.dumps({"timestamp": datetime.now().isoformat(), "data": data}))
return data
if len(sys.argv) > 1:
query = " ".join(sys.argv[1:])
results = search_with_cache(query)
for r in results.get("organic_results", [])[:5]:
print(f"[{r.get('position')}] {r.get('title', '')}")
print(f" {r.get('snippet', '')}")Implementacion en JavaScript
const fs = require('fs'), path = require('path'), crypto = require('crypto');
const CACHE_DIR = path.join(require('os').homedir(), '.search_cache');
if (!fs.existsSync(CACHE_DIR)) fs.mkdirSync(CACHE_DIR);
const H = {'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json'};
async function searchWithCache(query) {
const key = crypto.createHash('md5').update(query).digest('hex');
const cacheFile = path.join(CACHE_DIR, key+'.json');
if (fs.existsSync(cacheFile)) {
const cached = JSON.parse(fs.readFileSync(cacheFile,'utf8'));
if (Date.now() - new Date(cached.timestamp).getTime() < 86400000) return cached.data;
}
const r = await fetch('https://api.scavio.dev/api/v1/search', {method:'POST', headers:H, body:JSON.stringify({query, country_code:'us'})});
const data = await r.json();
fs.writeFileSync(cacheFile, JSON.stringify({timestamp:new Date().toISOString(), data}));
return data;
}
const q = process.argv.slice(2).join(' ');
const d = await searchWithCache(q);
(d.organic_results||[]).slice(0,5).forEach(r=>console.log('['+r.position+'] '+r.title));Plataformas utilizadas
Búsqueda web con grafo de conocimiento, PAA y resúmenes de IA