import requests
import json

awin_token = 'bebd7839-013a-434d-a3da-7db2ecefb6b1'
publisher_id = 374301
headers = {'Authorization': f'Bearer {awin_token}'}

# Get all joined programmes, look for sneaker shops
r = requests.get(f'https://api.awin.com/publishers/{publisher_id}/programmes?relationship=joined', headers=headers)
programmes = r.json()
print(f'Total joined programmes: {len(programmes)}')

sneaker_keywords = ['sneaker', 'shoe', 'schoen', 'footwear', 'sport', 'nike', 'adidas', 'puma', 'asics', 'zalando', 'jd', 'footlocker', 'snipes', 'size?']
for p in programmes:
    name = p.get('name', '')
    desc = p.get('description', '')[:100]
    combined = f'{name} {desc}'.lower()
    if any(kw in combined for kw in sneaker_keywords):
        print(f'  {p["id"]:>8} | {name[:40]:40} | {p.get("status","")}')

# Also try productdata download with specific advertiser
print('\n--- Trying product feed download ---')
# Try different format for datafeed
urls = [
    f'https://productdata.awin.com/datafeed/list/apikey/{awin_token}/',
    f'https://productdata.awin.com/datafeed/list/apikey/{awin_token}/language/nl/',
]
for url in urls:
    r = requests.get(url, timeout=15)
    print(f'{r.status_code}: {url[:80]}')
    if r.ok:
        print(f'  {r.text[:300]}')
