mirror of
https://github.com/nethunterzist/trendyol-analiz
synced 2026-07-03 10:17:03 +00:00
fix: collect_scrapable_categories should recurse to leaf categories
Ne yaptık: - Fonksiyon artık her zaman çocuk kategorilere iniyor - Sadece leaf (yaprak) kategorileri toplıyor — children'ı olan kategorileri atılıyor - Önceki davranış: trendyol_category_id varsa duruyordu, alt kategorilere inmiyordu Neden yaptık: - "Kadın" kategorisinde 17 üst kategori seçildiğinde sadece 17 kategori taranıyordu - Oysa bu 17 kategorinin altında yüzlerce leaf kategori var (ör: Ayakkabı→10, Aksesuar→35) - Şimdi tüm ağacın en dibine kadar inip tüm leaf kategorileri tarayacak Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1261,8 +1261,8 @@ def get_category_products(category_id: int, db: Session = Depends(get_db)):
|
|||||||
# Helper: recursively collect scrapable categories (those with trendyol_category_id)
|
# Helper: recursively collect scrapable categories (those with trendyol_category_id)
|
||||||
def collect_scrapable_categories(db: Session, category_ids: list) -> list:
|
def collect_scrapable_categories(db: Session, category_ids: list) -> list:
|
||||||
"""
|
"""
|
||||||
Given a list of category IDs, collect all categories with valid trendyol_category_id.
|
Given a list of category IDs, collect ALL leaf categories with valid trendyol_category_id.
|
||||||
If a category doesn't have trendyol_category_id, recursively check its children.
|
Always recurses into children to find every scrapable category in the tree.
|
||||||
Returns list of (trendyol_category_id, name) tuples.
|
Returns list of (trendyol_category_id, name) tuples.
|
||||||
"""
|
"""
|
||||||
result = []
|
result = []
|
||||||
@@ -1276,13 +1276,15 @@ def collect_scrapable_categories(db: Session, category_ids: list) -> list:
|
|||||||
if cat.id in seen:
|
if cat.id in seen:
|
||||||
continue
|
continue
|
||||||
seen.add(cat.id)
|
seen.add(cat.id)
|
||||||
if cat.trendyol_category_id:
|
# Check children first
|
||||||
result.append((cat.trendyol_category_id, cat.name))
|
children = db.query(Category).filter(Category.parent_id == cat.id).all()
|
||||||
else:
|
if children:
|
||||||
# No trendyol_category_id — check children
|
# Has children — recurse deeper
|
||||||
children = db.query(Category).filter(Category.parent_id == cat.id).all()
|
|
||||||
child_ids = [c.id for c in children]
|
child_ids = [c.id for c in children]
|
||||||
_collect(child_ids)
|
_collect(child_ids)
|
||||||
|
elif cat.trendyol_category_id:
|
||||||
|
# Leaf category with trendyol_category_id — add to results
|
||||||
|
result.append((cat.trendyol_category_id, cat.name))
|
||||||
|
|
||||||
_collect(category_ids)
|
_collect(category_ids)
|
||||||
return result
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user