fix(scraper): best seller siralamasi, tekrar eden urunler ve sosyal kanit bugu duzeltildi

Ne yaptik:
- scraper.py fetch_page: "sst": "BEST_SELLER" parametresi eklendi
- scraper.py fetch_page: "countryCode": "TR" parametresi eklendi
- scraper.py _normalize_search_product: socialProof (TEKIL) alanindan okunuyor,
  eski cogul socialProofs fallback olarak birakildi
- main.py _find_leaves: pathModel artik "<slug>-x-c<categoryId>" formatinda
  uretiliyor (queue_worker.py ile ayni mantik)

Neden yaptik:
- Trendyol Search API siralama parametresi verilmezse sayfalar arasi tutarsiz
  sonuc donuyordu: 240 urunluk cekimde sadece 134 benzersiz urun geliyordu,
  yani raporlarin %44'u ayni urunun tekrariydi. sst=BEST_SELLER ile tekrar
  tamamen sifirlandi (240/240 benzersiz)
- Sosyal kanit alani API'de TEKIL "socialProof" olarak geliyor ama kod cogul
  "socialProofs" diye okuyordu; bu yuzden satis/favori verisi hep bos donuyordu.
  Telafi icin cagrilan Top Rankings API ise Trendyol tarafinda kaldirildigi icin
  404 veriyor (K8s loglarinda dogrulandi). Duzeltmeden sonra 238/240 uruna
  orderCount ve favoriteCount geliyor
- countryCode zorunlu hale gelmis; yoksa API 400 "Required country information"
  donuyor
- main.py salt slug gonderiyordu (or. "yuz-kremi"), API 0 urun donuyordu.
  Dogru format "yuz-kremi-x-c1122"

Test:
- yuz-kremi-x-c1122, 10 sayfa: 240 urun / 240 benzersiz / 0 tekrar / 238 sosyal kanit
- Regresyon: 6 farkli kategori tipinde 6/6 basarili, tekrar yok

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
furkanyigit34
2026-08-13 18:34:59 +03:00
parent 016c540945
commit 9c5a85c589
2 changed files with 14 additions and 2 deletions

View File

@@ -1694,7 +1694,10 @@ async def create_report(
# This is a leaf — return itself # This is a leaf — return itself
cat = tree_by_id.get(parent_id) cat = tree_by_id.get(parent_id)
if cat: if cat:
path_model = (cat.get("url") or "").lstrip("/") or None # Trendyol pathModel formati: "<slug>-x-c<categoryId>" (or. yuz-kremi-x-c1122).
# Salt slug gonderilirse API 0 urun donuyor. queue_worker.py ile ayni mantik.
url_slug = (cat.get("url") or "").lstrip("/")
path_model = f"{url_slug}-x-c{cat['id']}" if url_slug else None
return [(path_model, cat["name"], cat["id"])] return [(path_model, cat["name"], cat["id"])]
return [] return []
leaves = [] leaves = []

View File

@@ -186,6 +186,12 @@ class TrendyolSearchScraper:
"pathModel": self.path_model, "pathModel": self.path_model,
"pi": page, "pi": page,
"ps": self.page_size, "ps": self.page_size,
# sst=BEST_SELLER: Trendyol'un cok satan siralamasi. Siralama parametresi
# verilmezse API sayfalar arasi tutarsiz sonuc donuyor — ayni urun farkli
# sayfalarda tekrar ediyor (240 urunluk cekimde ~%44 tekrar olctuk).
"sst": "BEST_SELLER",
# countryCode zorunlu oldu; yoksa API 400 "Required country information" doner
"countryCode": "TR",
"channelId": 1, "channelId": 1,
"storefrontId": 1, "storefrontId": 1,
"culture": "tr-TR" "culture": "tr-TR"
@@ -264,7 +270,10 @@ def _normalize_search_product(raw: dict) -> dict:
"imageUrl": raw.get("image", raw.get("imageUrl", "")), "imageUrl": raw.get("image", raw.get("imageUrl", "")),
"merchantListings": raw.get("merchantListings", []), "merchantListings": raw.get("merchantListings", []),
"winnerVariant": raw.get("winnerVariant", {}), "winnerVariant": raw.get("winnerVariant", {}),
"socialProofs": raw.get("socialProofs", []), # Search API alani TEKIL "socialProof" — cogul "socialProofs" diye okundugu icin
# bugune kadar hep bos donuyordu. Ic format cogul kaliyor (downstream kod ona bagli).
# Icerik: [{"key":"orderCount","value":"3000+"},{"key":"favoriteCount","value":"2M"}]
"socialProofs": raw.get("socialProof") or raw.get("socialProofs") or [],
"categoryId": raw.get("categoryId"), "categoryId": raw.get("categoryId"),
"categoryName": raw.get("categoryName"), "categoryName": raw.get("categoryName"),
} }