← back to Discontinued Fix
reverse.py
25 lines
#!/usr/bin/env python3
"""Reverse the discontinued fix: restore each product in data/restore-map.json to active.
DRY-RUN default; live requires --apply + DISC_FIX_CONFIRM=YES."""
import os, sys, json, time, 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")
def main():
live = "--apply" in sys.argv and os.environ.get("DISC_FIX_CONFIRM")=="YES"
rows = json.load(open(os.path.join(HERE,"data","restore-map.json")))
print(f"=== reverse [{'LIVE' if live else 'DRY-RUN'}] — {len(rows)} -> active ===")
tok = token() if live else None
for r in rows:
if not live: print(f"WOULD: {r['num']} -> {r['prev_status']}"); continue
try:
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']}")
except urllib.error.HTTPError as e: print(f"FAIL {r['num']} HTTP {e.code}")
time.sleep(0.4)
if __name__=="__main__": main()