import requests
import sys
sys.path.insert(0, r'C:\Users\Roel\clawd\scripts\demandgen-pipeline')
from config import WEBGAINS_API, PUBLISHER_ID, webgains_headers

campaigns = {
    'manify.nl': 1622230,
    'thehike.nl': 1622240,
    'ladify.nl': 1622250,
    'mellowed.nl': 1622260,
}

for name, cid in campaigns.items():
    print(f'\n=== {name} ({cid}) ===')
    # List feeds
    url = f'{WEBGAINS_API}/auth/publishers/{PUBLISHER_ID}/campaigns/{cid}/feeds'
    r = requests.get(url, headers=webgains_headers(), params={'size': 100})
    if not r.ok:
        print(f'  Error: {r.status_code}')
        continue
    feeds = r.json().get('data', [])
    sneaker_feeds = []
    for f in feeds:
        pname = f.get('program', {}).get('name', '')
        fname = f.get('name', '')
        count = f.get('products_successfully_stored', 0) or 0
        if count > 0:
            combined = f'{pname} {fname}'.lower()
            if any(kw in combined for kw in ['sneak', 'shoe', 'schoen', 'patta', 'basket', 'baskets', 'footwear', 'kick', 'nike', 'adidas', 'jordan']):
                sneaker_feeds.append(f)
                print(f'  SNEAKER: {f["id"]:>6} | {count:>6} | {pname[:30]:30} | {fname[:40]}')
            else:
                print(f'  other:  {f["id"]:>6} | {count:>6} | {pname[:30]:30} | {fname[:40]}')
    
    # Test products from first feed
    if feeds:
        furl = f'{WEBGAINS_API}/auth/publishers/{PUBLISHER_ID}/campaigns/{cid}/feeds/products'
        r2 = requests.get(furl, headers=webgains_headers(), params={'size': 3, 'fields[]': ['title','brand','price']})
        if r2.ok:
            for p in r2.json().get('data', []):
                print(f'  sample: {p.get("brand", "")} | {p.get("title", "")} | {p.get("price", "")}')
