#!/usr/bin/env python3 """按 GitHub API 的文件清单,用 raw 直取仓库文件(免 clone,应对慢镜像)。""" import json, time, urllib.request from pathlib import Path ROOT = Path(__file__).resolve().parent REPOS = ['ziniao-open/skills', 'ziniao-open/skill-hub', 'hubstudio-Max/hubstudio-skill'] UA = {'User-Agent': 'Mozilla/5.0'} ok = fail = 0 for r in REPOS: name = r.split('/')[-1] tree = json.load(open(ROOT / f'tree-{name}.json')) for t in tree.get('tree', []): if t['type'] != 'blob': continue dest = ROOT / 'repos' / name / t['path'] if dest.exists() and dest.stat().st_size > 0: ok += 1 continue dest.parent.mkdir(parents=True, exist_ok=True) for br in ('main', 'master'): url = f"https://raw.githubusercontent.com/{r}/{br}/{t['path']}" try: data = urllib.request.urlopen(urllib.request.Request(url, headers=UA), timeout=30).read() dest.write_bytes(data); ok += 1 break except Exception: # noqa: BLE001 time.sleep(0.5) else: fail += 1 print(' ❌', r, t['path'], flush=True) time.sleep(0.1) print(f' ✅ {r} 完成', flush=True) print(f'仓库文件: ok={ok} fail={fail}', flush=True)