Les produits qui deviennent viraux sur TikTok voient souvent leurs prix et stocks Amazon changer en quelques heures. Ce traqueur surveille les hashtags TikTok pour les mentions de produits, les associe aux listes Amazon et alerte sur les variations de prix. Chaque vérification TikTok coûte 0,005 $ et chaque recherche Amazon coûte 0,005 $, ce qui fait qu'un scan quotidien de 20 produits revient à 0,20 $.
Prérequis
- Python 3.8+
- bibliothèque requests
- Une clé API Scavio depuis scavio.dev
- Cibler des hashtags ou des créateurs à surveiller
Parcours
Étape 1: Scanner les hashtags TikTok pour les mentions de produits
Récupérer les vidéos récentes des hashtags de produits tendances et extraire les noms de produits.
import os, requests, re, json
API_KEY = os.environ['SCAVIO_API_KEY']
TT_H = {'Authorization': f'Bearer {API_KEY}', 'Content-Type': 'application/json'}
SH = {'x-api-key': API_KEY, 'Content-Type': 'application/json'}
def scan_hashtag(tag):
data = requests.post('https://api.scavio.dev/api/v1/tiktok/hashtag/videos',
headers=TT_H, json={'name': tag}).json()
videos = data.get('videos', data.get('data', {}).get('videos', []))[:20]
products = []
for v in videos:
desc = v.get('desc', v.get('description', ''))
if any(w in desc.lower() for w in ['link in bio', 'amazon', 'must have', 'under $']):
products.append({'desc': desc[:120], 'views': v.get('stats', {}).get('playCount', 0),
'author': v.get('author', {}).get('uniqueId', 'unknown')})
print(f'#{tag}: {len(videos)} videos, {len(products)} product mentions')
return products
products = scan_hashtag('amazonfinds')
for p in products[:3]: print(f' {p["desc"][:60]}... ({p["views"]:,} views)')Étape 2: Extraire les noms de produits et rechercher sur Amazon
Analyser les noms de produits dans les descriptions TikTok et trouver les listes Amazon correspondantes.
def extract_product(desc):
patterns = [r'([A-Z][\w\s]+(?:Pro|Max|Plus|Mini|Ultra)?)', r'the ([\w\s]+?) (?:is|from|on)']
for p in patterns:
m = re.search(p, desc)
if m: return m.group(1).strip()[:50]
words = desc.split()[:6]
return ' '.join(w for w in words if not w.startswith('#'))[:50]
def search_amazon(product_name):
data = requests.post('https://api.scavio.dev/api/v1/search',
headers=SH, json={'query': product_name, 'platform': 'amazon', 'country_code': 'us'}).json()
results = data.get('organic_results', data.get('shopping_results', []))[:3]
return [{'title': r.get('title', '')[:60], 'price': r.get('price', 'N/A'),
'rating': r.get('rating', 'N/A'), 'link': r.get('link', '')}
for r in results]
for p in products[:3]:
name = extract_product(p['desc'])
listings = search_amazon(name)
print(f'\n TikTok: {name}')
for l in listings: print(f' Amazon: {l["title"][:50]} - {l["price"]} ({l["rating"]})')Étape 3: Suivre les variations de prix dans le temps
Stocker les prix et détecter les mouvements entre les scans.
import json
from datetime import datetime
DB_FILE = 'tiktok_amazon_prices.json'
def load_db():
try:
with open(DB_FILE) as f: return json.load(f)
except: return {}
def save_db(db):
with open(DB_FILE, 'w') as f: json.dump(db, f, indent=2)
def track_price(product_name, amazon_listing):
db = load_db()
key = product_name.lower().strip()
price_str = str(amazon_listing.get('price', 'N/A')).replace('$', '').replace(',', '')
try: price = float(price_str)
except: return None
now = datetime.now().isoformat()
if key not in db: db[key] = []
prev = db[key][-1]['price'] if db[key] else price
change = ((price - prev) / prev * 100) if prev else 0
db[key].append({'price': price, 'date': now})
save_db(db)
if abs(change) > 5:
print(f' ALERT: {product_name} price moved {change:+.1f}% (${prev:.2f} -> ${price:.2f})')
return change
track_price('Stanley Cup', {'price': '$34.99'})
track_price('Stanley Cup', {'price': '$39.99'})Étape 4: Exécuter le pipeline complet de suivi
Combiner le scan de hashtags, la correspondance Amazon et le suivi des prix.
def run_tracker(hashtags):
all_alerts = []
total_cost = 0
for tag in hashtags:
products = scan_hashtag(tag)
total_cost += 0.005 # 1 TikTok API call
for p in products[:5]: # Top 5 per hashtag
name = extract_product(p['desc'])
listings = search_amazon(name)
total_cost += 0.005 # 1 Amazon search
for l in listings[:1]:
change = track_price(name, l)
if change and abs(change) > 5:
all_alerts.append({'product': name, 'change': change,
'price': l['price'], 'views': p['views']})
print(f'\nScanned {len(hashtags)} hashtags. Cost: ${total_cost:.3f}')
print(f'Price alerts: {len(all_alerts)}')
for a in all_alerts:
print(f' {a["product"]}: {a["change"]:+.1f}% -> {a["price"]} ({a["views"]:,} TikTok views)')
return all_alerts
run_tracker(['amazonfinds', 'tiktokmademebuyit'])Exemple Python
import os, requests
API_KEY = os.environ['SCAVIO_API_KEY']
TT_H = {'Authorization': f'Bearer {API_KEY}', 'Content-Type': 'application/json'}
SH = {'x-api-key': API_KEY, 'Content-Type': 'application/json'}
def track(hashtag):
vids = requests.post('https://api.scavio.dev/api/v1/tiktok/hashtag/videos',
headers=TT_H, json={'name': hashtag}).json()
videos = vids.get('videos', vids.get('data', {}).get('videos', []))[:10]
for v in videos[:3]:
desc = v.get('desc', '')[:50]
amz = requests.post('https://api.scavio.dev/api/v1/search',
headers=SH, json={'query': desc, 'platform': 'amazon', 'country_code': 'us'}).json()
top = (amz.get('organic_results') or [{}])[0]
print(f'TikTok: {desc}\n Amazon: {top.get("title", "N/A")[:40]} - {top.get("price", "N/A")}')
track('amazonfinds')Exemple JavaScript
const API_KEY = process.env.SCAVIO_API_KEY;
const TH = { 'Authorization': `Bearer ${API_KEY}`, 'Content-Type': 'application/json' };
const SH = { 'x-api-key': API_KEY, 'Content-Type': 'application/json' };
async function track(hashtag) {
const vids = await fetch('https://api.scavio.dev/api/v1/tiktok/hashtag/videos', {
method: 'POST', headers: TH, body: JSON.stringify({ name: hashtag })
}).then(r => r.json());
const videos = (vids.videos || vids.data?.videos || []).slice(0, 3);
for (const v of videos) {
const desc = (v.desc || '').slice(0, 50);
const amz = await fetch('https://api.scavio.dev/api/v1/search', {
method: 'POST', headers: SH,
body: JSON.stringify({ query: desc, platform: 'amazon', country_code: 'us' })
}).then(r => r.json());
const top = (amz.organic_results || [{}])[0];
console.log(`TikTok: ${desc}\n Amazon: ${(top.title||'N/A').slice(0,40)} - ${top.price||'N/A'}`);
}
}
track('amazonfinds').catch(console.error);Sortie attendue
#amazonfinds: 20 videos, 8 product mentions
Stanley Quencher H2.0 FlowState Tumbler... (2,400,000 views)
Dyson Airwrap Complete Long... (1,800,000 views)
TikTok: Stanley Quencher
Amazon: Stanley Quencher H2.0 FlowState Tumbler 40oz - $34.99 (4.7)
ALERT: Stanley Quencher price moved +14.3% ($30.62 -> $34.99)
Scanned 2 hashtags. Cost: $0.060
Price alerts: 1
Stanley Quencher: +14.3% -> $34.99 (2,400,000 TikTok views)