Les propriétaires de petites boutiques en ligne et les consultants en veille concurrentielle ont besoin d'instantanés de prix quotidiens sur deux ou trois places de marché. Les endpoints Amazon, Walmart et Google Shopping de Scavio alimentent un tracker avec le même format JSON. Ce tutoriel construit le pipeline de collecte quotidienne et d'alertes.
Prérequis
- Python 3.10+
- Clé API Scavio
- DuckDB ou Postgres
Parcours
Étape 1: Définir la liste de suivi
Liste de tuples (sku, label, sources).
WATCHLIST = [
('B08Z6HVSL5', 'lego star wars 75300', ['amazon', 'walmart', 'google_shopping']),
# add more...
]Étape 2: Récupérer le prix Amazon
Recherche par ASIN.
import requests, os
API_KEY = os.environ['SCAVIO_API_KEY']
def amazon_price(asin):
r = requests.post('https://api.scavio.dev/api/v1/amazon/product',
headers={'x-api-key': API_KEY},
json={'asin': asin})
return r.json().get('price')Étape 3: Récupérer le prix Walmart
Recherche de produit Walmart par ID.
def walmart_price(walmart_id):
r = requests.post('https://api.scavio.dev/api/v1/walmart/product',
headers={'x-api-key': API_KEY},
json={'product_id': walmart_id})
return r.json().get('price')Étape 4: Récupérer Google Shopping
La recherche shopping SERP renvoie les offres des marchands.
def shopping(query):
r = requests.post('https://api.scavio.dev/api/v1/google',
headers={'x-api-key': API_KEY},
json={'query': query, 'search_type': 'shopping'})
return r.json().get('shopping_results', [])Étape 5: Stocker et alerter
Ligne DuckDB par (sku, source, price, date) ; alerter en cas de baisse seuil.
import duckdb
db = duckdb.connect('prices.duckdb')
db.execute('CREATE TABLE IF NOT EXISTS prices(sku TEXT, source TEXT, price FLOAT, date DATE)')
def alert_if_drop(sku, source, price):
last = db.execute('SELECT price FROM prices WHERE sku=? AND source=? ORDER BY date DESC LIMIT 1', (sku, source)).fetchone()
if last and price < last[0] * 0.9:
# send alert
passExemple Python
import os, requests
API_KEY = os.environ['SCAVIO_API_KEY']
def snapshot(asin, walmart_id, query):
a = requests.post('https://api.scavio.dev/api/v1/amazon/product',
headers={'x-api-key': API_KEY}, json={'asin': asin}).json()
w = requests.post('https://api.scavio.dev/api/v1/walmart/product',
headers={'x-api-key': API_KEY}, json={'product_id': walmart_id}).json()
g = requests.post('https://api.scavio.dev/api/v1/google',
headers={'x-api-key': API_KEY}, json={'query': query, 'search_type': 'shopping'}).json()
return {'amazon': a.get('price'), 'walmart': w.get('price'), 'shopping': g.get('shopping_results',[])[:5]}
print(snapshot('B08Z6HVSL5', 'WL12345', 'lego 75300'))Exemple JavaScript
const API_KEY = process.env.SCAVIO_API_KEY;
export async function snapshot(asin, walmartId, query) {
const headers = { 'x-api-key': API_KEY, 'Content-Type': 'application/json' };
const [a, w, g] = await Promise.all([
fetch('https://api.scavio.dev/api/v1/amazon/product', { method:'POST', headers, body: JSON.stringify({ asin }) }).then(r => r.json()),
fetch('https://api.scavio.dev/api/v1/walmart/product', { method:'POST', headers, body: JSON.stringify({ product_id: walmartId }) }).then(r => r.json()),
fetch('https://api.scavio.dev/api/v1/google', { method:'POST', headers, body: JSON.stringify({ query, search_type: 'shopping' }) }).then(r => r.json())
]);
return { a, w, g };
}Sortie attendue
Daily price snapshots per SKU across Amazon, Walmart, and Google Shopping. Alerts fire on >10% price drops. DuckDB stores history for trend analysis.