Resumen
Este flujo de trabajo verifica prices for un producto watchlist a traves de Amazon y Walmart cada dia, compara contra almacenado baselines, y fires alertas cuando prices cambio by mas than un configurable umbral. It maintains un price history for analisis de tendencias y produces un diario resumen of todos price movements.
Desencadenador
Cron programar (diario at 8:00 AM UTC)
Programación
Ejecuta diario at 8:00 AM UTC
Pasos del flujo de trabajo
Cargar producto watchlist
Leer el lista of productos to monitorear con their actual linea base prices de storage.
Obtener actual prices de Amazon y Walmart
Call Scavio search for cada producto on ambos Amazon y Walmart plataformas.
Comparar contra baselines
Calcular absolute y porcentaje cambios de precio contra almacenado baselines for cada producto y plataforma.
Generar alertas for significativo cambios
Marcar productos donde price changed mas than el configured umbral (default 5%) y categorizar as caida o aumento.
Actualizar baselines y archive history
Escribir actual prices back to linea base storage y agregar to price history for tendencia charts.
Implementacion en Python
import requests
import json
from pathlib import Path
from datetime import datetime
API_KEY = "your_scavio_api_key"
THRESHOLD_PCT = 5.0
WATCHLIST = [
{"slug": "airpods-pro", "query": "airpods pro 2", "platforms": ["amazon", "walmart"]},
{"slug": "ps5", "query": "playstation 5 console", "platforms": ["amazon", "walmart"]},
{"slug": "kindle", "query": "kindle paperwhite 2024", "platforms": ["amazon", "walmart"]},
]
def get_price(query: str, platform: str) -> float | None:
res = requests.post(
"https://api.scavio.dev/api/v1/search",
headers={"x-api-key": API_KEY},
json={"platform": platform, "query": query},
timeout=15,
)
res.raise_for_status()
for item in res.json().get("organic", []):
if item.get("price"):
return float(item["price"])
return None
def run():
date = datetime.utcnow().strftime("%Y-%m-%d")
baseline_path = Path("price_baselines.json")
baselines = json.loads(baseline_path.read_text()) if baseline_path.exists() else {}
alerts = []
for product in WATCHLIST:
for platform in product["platforms"]:
key = f"{product['slug']}_{platform}"
current_price = get_price(product["query"], platform)
previous_price = baselines.get(key)
if current_price and previous_price:
pct_change = ((current_price - previous_price) / previous_price) * 100
if abs(pct_change) >= THRESHOLD_PCT:
alerts.append({
"product": product["query"],
"platform": platform,
"previous": previous_price,
"current": current_price,
"change_pct": round(pct_change, 1),
"direction": "drop" if pct_change < 0 else "increase",
})
if current_price:
baselines[key] = current_price
baseline_path.write_text(json.dumps(baselines, indent=2))
# Append to history
history_path = Path("price_history.jsonl")
with history_path.open("a") as f:
f.write(json.dumps({"date": date, "prices": baselines}) + "\n")
print(f"Price check complete: {len(WATCHLIST)} products, {len(alerts)} alerts")
for a in alerts:
print(f" {a['direction'].upper()}: {a['product']} on {a['platform']}: ${a['previous']:.2f} -> ${a['current']:.2f} ({a['change_pct']:+.1f}%)")
if __name__ == "__main__":
run()Implementacion en JavaScript
const API_KEY = "your_scavio_api_key";
const THRESHOLD_PCT = 5.0;
const WATCHLIST = [
{ slug: "airpods-pro", query: "airpods pro 2", platforms: ["amazon", "walmart"] },
{ slug: "ps5", query: "playstation 5 console", platforms: ["amazon", "walmart"] },
];
async function getPrice(query, platform) {
const res = await fetch("https://api.scavio.dev/api/v1/search", {
method: "POST",
headers: { "x-api-key": API_KEY, "content-type": "application/json" },
body: JSON.stringify({ platform, query }),
});
if (!res.ok) throw new Error(`scavio ${res.status}`);
for (const item of (await res.json()).organic ?? []) {
if (item.price) return Number(item.price);
}
return null;
}
async function run() {
const fs = await import("fs/promises");
let baselines = {};
try { baselines = JSON.parse(await fs.readFile("price_baselines.json", "utf8")); } catch {}
const alerts = [];
for (const product of WATCHLIST) {
for (const platform of product.platforms) {
const key = `${product.slug}_${platform}`;
const current = await getPrice(product.query, platform);
const previous = baselines[key];
if (current && previous) {
const pct = ((current - previous) / previous) * 100;
if (Math.abs(pct) >= THRESHOLD_PCT) alerts.push({ product: product.query, platform, previous, current, changePct: Math.round(pct * 10) / 10 });
}
if (current) baselines[key] = current;
}
}
await fs.writeFile("price_baselines.json", JSON.stringify(baselines, null, 2));
console.log(`${WATCHLIST.length} products checked, ${alerts.length} alerts`);
for (const a of alerts) console.log(` ${a.product} on ${a.platform}: $${a.previous} -> $${a.current} (${a.changePct}%)`);
}
run();Plataformas utilizadas
Amazon
Búsqueda de productos con precios, calificaciones y reseñas
Walmart
Búsqueda de productos con precios y datos de cumplimiento