Files
liqiang b119135836
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
2026-08-20 13:12:50 +00:00

85 lines
2.8 KiB
Python

#! /usr/bin/env python3
"""Upload EPUB to GitHub fork"""
import json, base64, sys, requests
sys.stdout.reconfigure(line_buffering=True)
TOKEN = "ghp_jy…4OXJ"
OWNER = "barmivalami0-ux"
REPO = "ai-agent-book"
FILE = "/home/leno/.openclaw/workspace/book-hu/AI-Agent-Book_HU.epub"
HEADERS = {"Authorization": f"token {TOKEN}", "Accept": "application/vnd.github.v3+json"}
API = "https://api.github.com"
def api(method, path, data=None):
r = requests.request(method, f"{API}{path}", headers=HEADERS, json=data, timeout=120)
if r.status_code not in (200, 201):
print(f"❌ {method} {path}: {r.status_code} {r.text[:100]}")
return None
return r.json()
# Get base
base = api("GET", f"/repos/{OWNER}/{REPO}/git/refs/heads/main")
if not base: sys.exit(1)
base_sha = base["object"]["sha"]
print(f"Base commit: {base_sha[:8]}")
commit = api("GET", f"/repos/{OWNER}/{REPO}/git/commits/{base_sha}")
tree_sha = commit["tree"]["sha"]
print(f"Base tree: {tree_sha[:8]}")
# Create blob from EPUB
with open(FILE, "rb") as f:
content = base64.b64encode(f.read()).decode("ascii")
print(f"EPUB base64: {len(content)} chars")
blob = api("POST", f"/repos/{OWNER}/{REPO}/git/blobs", {
"content": content, "encoding": "base64"
})
if not blob: sys.exit(1)
blob_sha = blob["sha"]
print(f"EPUB blob: {blob_sha[:8]}")
# Get current tree
tree_data = api("GET", f"/repos/{OWNER}/{REPO}/git/trees/{tree_sha}")
tree_items = tree_data["tree"]
# Add EPUB file to tree
tree_items.append({
"path": "book-hu/AI-Agent-Book_HU.epub",
"mode": "100644",
"type": "blob",
"sha": blob_sha
})
# Create new tree
new_tree = api("POST", f"/repos/{OWNER}/{REPO}/git/trees", {
"base_tree": tree_sha,
"tree": tree_items
})
if not new_tree: sys.exit(1)
new_tree_sha = new_tree["sha"]
print(f"New tree: {new_tree_sha[:8]}")
# Create commit
new_commit = api("POST", f"/repos/{OWNER}/{REPO}/git/commits", {
"message": "📱 Add EPUB fájl a könnyű letöltésért\n\nAz AI Agent - Tervezési elvek és gyakorlat magyar fordítása EPUB formátumban, 132 beágyazott ábrával.",
"tree": new_tree_sha,
"parents": [base_sha],
"author": {"name": "Ady AI", "email": "ady-ai@users.noreply.github.com"},
"committer": {"name": "Ady AI", "email": "ady-ai@users.noreply.github.com"}
})
if not new_commit: sys.exit(1)
print(f"Commit: {new_commit['sha'][:8]}")
# Update ref
result = api("PATCH", f"/repos/{OWNER}/{REPO}/git/refs/heads/main", {
"sha": new_commit["sha"], "force": False
})
if result:
print(f"\n🎉 EPUB felkerült a GitHub-ra!")
print(f" https://github.com/{OWNER}/{REPO}/blob/main/book-hu/AI-Agent-Book_HU.epub")
print(f"\n📥 Közvetlen letöltés (bárki számára):")
print(f" https://raw.githubusercontent.com/{OWNER}/{REPO}/main/book-hu/AI-Agent-Book_HU.epub")
else:
print("❌ Hiba")