#!/usr/bin/env python3
import json, urllib.request, urllib.parse

token = None
for line in open("/root/site/yandex/.env", encoding="utf-8"):
    if line.startswith("YANDEX_ACCESS_TOKEN="):
        token = line.split("=", 1)[1].strip()

def api(path):
    url = "https://cloud-api.yandex.net/v1/disk/resources?path=" + urllib.parse.quote(path)
    req = urllib.request.Request(url, headers={"Authorization": f"OAuth {token}"})
    with urllib.request.urlopen(req, timeout=30) as r:
        return json.loads(r.read().decode())

BASE = "/Добротный дом рендеры/Добротный 1.0 Троицкий"
subs = ["Фото ", "Проект", "Видео обзор дома", "Видео", "КП", "Вывеска"]
for sub in subs:
    try:
        d = api(BASE + "/" + sub)
        items = d.get("_embedded", {}).get("items", [])
        print(f"=== {sub} ({len(items)}) ===")
        for i in items[:40]:
            print(f"  [{i['type']}] {i['name']} ({i.get('size', '')})")
    except Exception as e:
        print(f"=== {sub} === ERROR {e}")
