← back to Zero Price Fix
reverse.py
17 lines
#!/usr/bin/env python3
"""Reverse: restore PR Elowen to its prev status. DRY-RUN default; live needs --apply + ZEROFIX_CONFIRM=YES."""
import os,sys,json,urllib.request,urllib.error
HERE=os.path.dirname(os.path.abspath(__file__)); SHOP="designer-laboratory-sandbox.myshopify.com"; API="2024-10"
def token():
for l in open(os.path.expanduser("~/Projects/secrets-manager/.env")):
if l.startswith("SHOPIFY_ADMIN_TOKEN="): return l.split("=",1)[1].strip()
sys.exit("no token")
live="--apply" in sys.argv and os.environ.get("ZEROFIX_CONFIRM")=="YES"
for r in json.load(open(os.path.join(HERE,"data","worklist.json"))):
if not live: print(f"WOULD: {r['num']} -> {r['prev_status']}"); continue
tok=token()
req=urllib.request.Request(f"https://{SHOP}/admin/api/{API}/products/{r['num']}.json",
data=json.dumps({"product":{"id":int(r['num']),"status":r['prev_status']}}).encode(),method="PUT",
headers={"X-Shopify-Access-Token":tok,"Content-Type":"application/json"})
urllib.request.urlopen(req,timeout=40); print(f"OK: {r['num']} -> {r['prev_status']}")