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w6XI"

FEEDS = [("17108", "Van Arendonk"), ("36168", "Patta"), ("18588", "Baskets")]
BASE = "https://platform-api.webgains.com/auth/publishers/1347930/campaigns/1622230/feeds/products"

for fid, name in FEEDS:
    url = f"{BASE}?feedIds[]={fid}&format=csv"
    r = requests.get(url, headers={"Authorization": f"Bearer {TOKEN}"}, timeout=60)
    reader = csv.DictReader(io.StringIO(r.text))
    rows = list(reader)
    
    print(f"\n=== {name} ({fid}) — {len(rows)} rows ===")
    print(f"Columns: {reader.fieldnames}")
    
    # Find sneaker-like rows
    sneaker_brands = {'nike', 'adidas', 'new balance', 'puma', 'asics', 'jordan', 'converse', 'vans'}
    found = 0
    for row in rows:
        brand = (row.get('brand') or '').lower()
        title = (row.get('title') or '').lower()
        gcat = row.get('google_product_category') or row.get('google_product_category_text') or ''
        ptype = row.get('product_type') or ''
        if brand in sneaker_brands or 'sneaker' in title:
            if found < 3:
                print(f"\n  Brand: {row.get('brand')}")
                print(f"  Title: {row.get('title')}")
                print(f"  google_product_category: {gcat}")
                print(f"  product_type: {ptype}")
                print(f"  google_product_category_text: {row.get('google_product_category_text', 'N/A')}")
            found += 1
    print(f"  Found {found} sneaker-brand rows out of {len(rows)}")
