#!/usr/bin/env python3
"""Parse Awin feed list and find sneaker-relevant NL feeds."""
import requests
import csv
import io

url = "https://ui.awin.com/productdata-darwin-download/publisher/374301/489bdc79c6362be4f7d60e6b2506a2de/1/feedList"
r = requests.get(url, timeout=30)
reader = csv.DictReader(io.StringIO(r.text))

sneaker_keywords = ['shoe', 'sneaker', 'footwear', 'sport', 'jd', 'foot locker', 'schuurman', 'bever', 'nike', 'adidas', 'puma', 'asics', 'vans', 'converse', 'new balance', 'zalando', 'omoda', 'nelson', 'van haren', 'sarenza', 'torfs']
nl_regions = ['NL', 'BE']

print("=== ALL FEEDS ===")
all_feeds = []
for row in reader:
    all_feeds.append(row)

print(f"Total feeds: {len(all_feeds)}")

# Filter for NL/BE region or sneaker-related
print(f"\n=== NL/BE FEEDS ===")
for row in sorted(all_feeds, key=lambda x: x.get('Advertiser Name', '')):
    region = row.get('Primary Region', '')
    name = row.get('Advertiser Name', '').lower()
    products = row.get('No of products', '0')
    status = row.get('Membership Status', '')
    feed_id = row.get('Feed ID', '')
    feed_url = row.get('URL', '')
    
    if region in nl_regions:
        print(f"  [{region}] {row['Advertiser Name']} ({products} products) - {status} - {feed_id}")
        print(f"    URL: {feed_url}")

print(f"\n=== SNEAKER-RELEVANT (any region) ===")
for row in sorted(all_feeds, key=lambda x: -int(x.get('No of products', '0'))):
    name = row.get('Advertiser Name', '').lower()
    region = row.get('Primary Region', '')
    products = row.get('No of products', '0')
    status = row.get('Membership Status', '')
    feed_id = row.get('Feed ID', '')
    
    if any(kw in name for kw in sneaker_keywords):
        print(f"  [{region}] {row['Advertiser Name']} ({products} products) - {status} - {feed_id}")
