#!/usr/bin/env python3
"""Upload the just-built OTA zip to the expo-ota server via the authenticated
/uupload/upload multipart endpoint (the working df54/df55 path — NOT the raw
/uploads POST which 401s now)."""
import requests, json

BASE = "https://ota.46-4-121-190.sslip.io"
KEY = "cc7efb8608cab27f28254da1e30c1a1b"
ZIP = r"C:\Users\danam\SGT-FANTASTIC-08-06-26\Local\PixieSprout\pixiesprout-ota.zip"
OUT = r"C:\Users\danam\SGT-FANTASTIC-08-06-26\Local\PixieSprout\upload_resp11.json"

for attempt in range(1, 4):
    try:
        r = requests.post(
            f"{BASE}/upload",
            files={"uri": open(ZIP, "rb")},
            headers={"project": "pixiesprout", "version": "1.0.116",
                     "release-channel": "default", "upload-key": KEY},
            timeout=880,
        )
        print("HTTP", r.status_code, "in", round(r.elapsed.total_seconds(), 1), "s")
        open(OUT, "w").write(r.text[:2000])
        try:
            d = r.json()
            print("uploadId:", d.get("uploadId"))
            print("updateId:", d.get("updateId"))
        except Exception:
            print("non-JSON body:", r.text[:500])
        break
    except Exception as e:
        print(f"attempt {attempt} failed: {type(e).__name__}: {e}")
