import json
from urllib.request import Request, urlopen
import base64

BASE = "https://ota.46-4-121-190.sslip.io"
# We'll query the DB directly via the docker mongo instead
# Just print available uploads from the filesystem listing of metadata.json
import glob, os
for f in sorted(glob.glob("/opt/expo-ota/updates/pixiesprout/*/*/metadata.json")):
    d = os.path.dirname(f)
    ver = d.split("/")[-2]
    uid = d.split("/")[-1]
    appj = os.path.join(d, "app.json")
    ver_nm = "?"
    if os.path.exists(appj):
        try:
            ver_nm = json.load(open(appj)).get("version", "?")
        except Exception:
            pass
    print("v=%s id=%s appVer=%s" % (ver, uid, ver_nm))
