import json, os, requests

# Lecture du token
with open(r"C:\ASSISTANT_IA\.env") as f:
    for line in f:
        if line.startswith("SHOPIFY_ACCESS_TOKEN="):
            token = line.strip().split("=", 1)[1]
            break

# Lecture du template
with open(r"C:\ASSISTANT_IA\theme_work\ref\product.sneaksafe.json", encoding="utf-8") as f:
    template = f.read()

headers = {
    "X-Shopify-Access-Token": token,
    "Content-Type": "application/json"
}

body = json.dumps({
    "asset": {
        "key": "templates/product.sneaksafe.json",
        "value": template
    }
})

r = requests.put(
    "https://vs1j6z-j0.myshopify.com/admin/api/2024-01/themes/134782386382/assets.json",
    headers=headers,
    data=body
)

print(f"Status: {r.status_code}")
if r.status_code == 200:
    print("✓ Template uploadé avec succès")
    print(f"  Taille : {len(template)} caractères")
else:
    print(f"✗ Erreur : {r.text}")
