import json
from urllib.request import Request, urlopen

BASE = "https://ota.46-4-121-190.sslip.io"

def api(method, path, data=None, token=None):
    headers = {"Content-Type": "application/json"}
    if token:
        headers["Authorization"] = "Bearer " + token
    body = json.dumps(data).encode() if data else None
    req = Request(BASE + path, data=body, headers=headers, method=method)
    with urlopen(req) as r:
        return json.loads(r.read())

t = api("POST", "/authentication", {"strategy": "local", "username": "admin", "password": "353fde0a0fe4e8a0b2799e54"})["accessToken"]
h = {"Authorization": "Bearer " + t, "Content-Type": "application/json"}
req = Request(BASE + "/uploads", headers=h)
data = json.loads(urlopen(req).read())
ups = data.get("data", data) if isinstance(data, dict) else data
rel = [u for u in ups if u.get("status") == "released"]
for u in rel:
    uid = u.get("updateId", "?")
    print("RELEASED:", u["_id"], "version=", u.get("version"), "updateId=", str(uid)[:12])
print("COUNT_RELEASED:", len(rel))
