mirror of
https://github.com/nethunterzist/trendyol-analiz
synced 2026-07-01 09:27: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)
|
||||
def collect_scrapable_categories(db: Session, category_ids: list) -> list:
|
||||
"""
|
||||
Given a list of category IDs, collect all categories with valid trendyol_category_id.
|
||||
If a category doesn't have trendyol_category_id, recursively check its children.
|
||||
Given a list of category IDs, collect ALL leaf categories with valid trendyol_category_id.
|
||||
Always recurses into children to find every scrapable category in the tree.
|
||||
Returns list of (trendyol_category_id, name) tuples.
|
||||
"""
|
||||
result = []
|
||||
@@ -1276,13 +1276,15 @@ def collect_scrapable_categories(db: Session, category_ids: list) -> list:
|
||||
if cat.id in seen:
|
||||
continue
|
||||
seen.add(cat.id)
|
||||
if cat.trendyol_category_id:
|
||||
result.append((cat.trendyol_category_id, cat.name))
|
||||
else:
|
||||
# No trendyol_category_id — check children
|
||||
children = db.query(Category).filter(Category.parent_id == cat.id).all()
|
||||
# Check children first
|
||||
children = db.query(Category).filter(Category.parent_id == cat.id).all()
|
||||
if children:
|
||||
# Has children — recurse deeper
|
||||
child_ids = [c.id for c in children]
|
||||
_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)
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user