← back to Dw Theme Live Signin Split
upload_tk11020.py
45 lines
import os,sys,json,urllib.request,time
tok=os.popen("grep -E '^SHOPIFY_THEME_TOKEN=' ~/Projects/secrets-manager/.env | cut -d= -f2-").read().strip()
DOMAIN="designer-laboratory-sandbox.myshopify.com"; THEME="145121607731"
KEY="snippets/dw-samples-banner.liquid"
val=open(KEY).read()
LEDGER=os.path.expanduser("~/.claude/yolo-queue/executed-reversible/ledger.jsonl")
def put(value):
body=json.dumps({"asset":{"key":KEY,"value":value}}).encode()
req=urllib.request.Request(f"https://{DOMAIN}/admin/api/2024-10/themes/{THEME}/assets.json",
data=body, method="PUT",
headers={"X-Shopify-Access-Token":tok,"Content-Type":"application/json"})
return urllib.request.urlopen(req,timeout=45)
def get_asset():
req=urllib.request.Request(f"https://{DOMAIN}/admin/api/2024-10/themes/{THEME}/assets.json?asset[key]={KEY}",
headers={"X-Shopify-Access-Token":tok})
return json.loads(urllib.request.urlopen(req,timeout=45).read())["asset"]["value"]
# GUARD: this PUTs to the LIVE production theme. Default to a no-op dry-run so a
# bare `python3 upload_tk11020.py` (stale terminal / copied pattern) can't
# overwrite the live theme; require --apply to actually write.
if "--apply" not in sys.argv:
cur=get_asset()
print(f"DRY-RUN (no write). {KEY}: {'CHANGED' if cur!=val else 'identical'} "
f"(live {len(cur)}B -> local {len(val)}B). Re-run with --apply to write.")
sys.exit(0)
r=put(val)
print("upload status:", r.status)
got=get_asset()
ok = "/pages/trade-only-benefits\">Trade Sign In" in got
print("verify trade-signin-link-live-in-theme:", ok)
# Only record the reversible-ledger row on a VERIFIED write — never claim success
# for an unmeasured/failed check (false-green class).
if not ok:
print("VERIFY FAILED — live write NOT confirmed, not ledgering"); sys.exit(1)
with open(LEDGER,"a") as f:
f.write(json.dumps({"ts":time.strftime("%Y-%m-%dT%H:%M:%S%z"),"agent":"claude-run-10456",
"ticket":"TK-11020","action":f"upload {KEY} to live theme {THEME} (add Trade Sign In link, Steve-approved)",
"blast_radius":1,
"undo_cmd":f"PUT theme {THEME} asset {KEY} = snippets/dw-samples-banner.liquid.baseline",
"verify":"GET asset contains trade-only-benefits Trade Sign In link"})+"\n")
print("ledgered.")