CoolFace
Apppublic

LZ-SG/embedded-dev-tutorials

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
push_spa2.py31 linesDownload Raw Back to root
1#!/usr/bin/env python32import base64, json, urllib.request, os3TOKEN = "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"4REPO = "sg06231219-boop/embedded-dev-tutorials"5BASE = os.path.dirname(os.path.abspath(__file__))6 7for path in ["app.py", "static/index.html"]:8    local = os.path.join(BASE, path.replace("/", os.sep))9    with open(local, "rb") as f:10        content = base64.b64encode(f.read()).decode()11    try:12        r = urllib.request.Request(13            f"https://api.github.com/repos/{REPO}/contents/{path}?ref=main",14            headers={"Authorization": f"token {TOKEN}", "Accept": "application/vnd.github.v3+json", "User-Agent": "push"})15        with urllib.request.urlopen(r, timeout=15) as resp:16            sha = json.loads(resp.read()).get("sha")17        payload = json.dumps({18            "message": "feat: v1.5.1 SPA bookmark+progress+sort",19            "content": content, "branch": "main", "sha": sha20        })21        r2 = urllib.request.Request(22            f"https://api.github.com/repos/{REPO}/contents/{path}",23            data=payload.encode(),24            headers={"Authorization": f"token {TOKEN}", "Content-Type": "application/json",25                     "Accept": "application/vnd.github.v3+json", "User-Agent": "push"})26        with urllib.request.urlopen(r2, timeout=20) as resp:27            result = json.loads(resp.read())28            print(f"OK {path} commit={result.get('commit',{}).get('sha','?')[:7]}")29    except Exception as e:30        print(f"FAIL {path}: {e}")31