Files
browser-docs-archive/mirror_repos.py
T
admin9webs 322b7737eb archive: 紫鸟/HubStudio 文档快照(3889 篇 Markdown)
来源:紫鸟帮助中心/博客/主站资讯 + HubStudio API 文档/帮助中心 + 三个官方 skill 仓库。
只入库 Markdown 与元数据;原始 HTML 与 tarball 留在本机。
2026-10-05 12:11:35 +00:00

34 lines
1.3 KiB
Python

#!/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)