← back to Secrets Manager

publish-creatures-article.py

96 lines

#!/usr/bin/env python3
"""
publish-creatures-article.py — one-shot: publish the AEO-optimized "Creatures of the
Night by Zak and Fox" DW blog article via the Shopify Admin API.

SAFE BY DESIGN:
  • Backs up the current body_html to /tmp/dw-drafts/creatures-ORIGINAL-body-backup.html
    BEFORE writing (instant revert path).
  • PRESERVES the existing 3 images + the poem block verbatim — wraps AEO content
    (direct-answer line + editorial above, question-H2s + FAQ + FAQPage JSON-LD below).
  • Sets the SEO title_tag + description_tag metafields.
Run it yourself:  ! python3 ~/Projects/secrets-manager/publish-creatures-article.py
"""
import re, json, urllib.request, sys

env = open('/Users/macstudio3/Projects/secrets-manager/.env').read()
tok = re.search(r'^SHOPIFY_DRAFT_TOKEN=(.+)$', env, re.M).group(1).strip().strip('"').strip("'")
STORE = "designer-laboratory-sandbox.myshopify.com"; API = "2024-10"
BLOG = 9243689072; ART = 561218191411

def get(path):
    req = urllib.request.Request(f"https://{STORE}/admin/api/{API}/{path}",
                                 headers={"X-Shopify-Access-Token": tok})
    return json.load(urllib.request.urlopen(req, timeout=30))

def put(path, payload):
    data = json.dumps(payload).encode()
    req = urllib.request.Request(f"https://{STORE}/admin/api/{API}/{path}", data=data,
        method="PUT", headers={"X-Shopify-Access-Token": tok, "Content-Type": "application/json"})
    return json.load(urllib.request.urlopen(req, timeout=30))

art = get(f"blogs/{BLOG}/articles/{ART}.json")['article']
orig_body = art.get('body_html') or ''
import os
os.makedirs("/tmp/dw-drafts", exist_ok=True)
open("/tmp/dw-drafts/creatures-ORIGINAL-body-backup.html", "w").write(orig_body)
print(f"backup saved ({len(orig_body)} chars) -> /tmp/dw-drafts/creatures-ORIGINAL-body-backup.html")

intro = '''<p>Creatures of the Night is a dark, nocturnal luxury wallcovering by the New York design house Zak and Fox.</p>

<p>The pattern reads like a midnight tapestry — shadowed forms and glinting eyes woven into a moody, hand-drawn motif. It belongs to Zak and Fox's signature vocabulary of artisanal, globally-inspired prints on natural grounds, and <a href="https://www.zakandfox.com">Zak and Fox</a> is carried by Designer Wallcoverings as an authorized luxury source with sampling and made-to-order production.</p>

<p>Because the design leans deep and atmospheric, it rewards spaces you want to feel intimate and theatrical: a powder room, a dining room, a study, or a single accent wall behind a bed. Paired with warm, low lighting and rich textures — velvet, aged brass, dark timber — the nocturnal motif comes alive rather than reading flat. Designers often reach for a statement pattern like this exactly where a quieter paper would disappear.</p>

<p>Installation follows standard luxury-wallcovering practice: professional hanging is recommended, and because the goods are made to order, lead times run longer than a stock roll. Order enough to cover the full run plus pattern-match overage in one batch so every drop comes from the same dye lot, and prep the walls properly before hanging.</p>

<p>As with most luxury wallcoverings, Creatures of the Night is produced to order. Designer Wallcoverings offers up to 10 free samples so you can test the colorway and scale in your own light before committing, and can custom design and print a coordinating pattern if you need a bespoke variation. For trade accounts, pricing and lead times are quoted per project — <a href="https://designerwallcoverings.com/pages/contact">contact the DW team</a> to start an order.</p>
'''

faq_pairs = [
 ("What is Creatures of the Night wallpaper by Zak and Fox?", "Creatures of the Night is a dark, nocturnal-themed luxury wallcovering from the New York design house Zak and Fox, known for artisanal, globally-inspired patterns. Its moody, tapestry-like motif is built for dramatic, statement interiors."),
 ("Who is Zak and Fox?", "Zak and Fox is a New York-based textile and wallcovering design studio founded by Zak Profera, recognized for hand-crafted, ethnographically-inspired prints on natural grounds. Designer Wallcoverings carries the line as an authorized luxury source."),
 ("Can I order free samples of Creatures of the Night before buying?", "Yes. Designer Wallcoverings offers up to 10 free samples so you can check the colorway and scale against your own lighting and furnishings before committing to a full order."),
 ("Is Creatures of the Night made to order?", "Yes. Like most luxury wallcoverings, it is produced to order, and Designer Wallcoverings can also custom design and print a coordinating pattern if you need a bespoke variation."),
 ("What rooms suit a dark, dramatic wallpaper like Creatures of the Night?", "Deep, atmospheric patterns work best in spaces you want to feel enveloping: powder rooms, dining rooms, studies, bedrooms, and accent walls. Pair with warm lighting and rich textures to amplify the nocturnal mood."),
]
h2s = '''<h2>What is Creatures of the Night wallpaper?</h2>
<p>A dark, tapestry-like luxury wallcovering from Zak and Fox, built around a nocturnal motif of shadowed creatures — designed to make a dramatic statement rather than sit quietly in the background.</p>

<h2>Who designs Creatures of the Night?</h2>
<p>Zak and Fox, a New York textile and wallcovering studio founded by Zak Profera, known for hand-crafted, ethnographically-inspired patterns printed on natural grounds.</p>

<h2>How do you order Creatures of the Night by Zak and Fox?</h2>
<p>Start with up to 10 free samples from Designer Wallcoverings to confirm the colorway and scale, then request a quote for made-to-order production. Contact the DW team for trade pricing and lead times before placing the full order.</p>

<h2>What rooms suit a dark wallpaper like this?</h2>
<p>Enveloping patterns work best in powder rooms, dining rooms, studies, bedrooms, and accent walls — spaces where a bold, moody backdrop adds drama instead of overwhelming an already-bright, high-traffic room.</p>
'''
faq_html = '<h2>Frequently Asked Questions</h2>\n' + ''.join(f'<h3>{q}</h3>\n<p>{a}</p>\n' for q, a in faq_pairs)
schema = {"@context": "https://schema.org", "@type": "FAQPage",
          "mainEntity": [{"@type": "Question", "name": q,
                          "acceptedAnswer": {"@type": "Answer", "text": a}} for q, a in faq_pairs]}
schema_html = '<script type="application/ld+json">\n' + json.dumps(schema, ensure_ascii=False, indent=2) + '\n</script>'

new_body = intro + "\n" + orig_body + "\n" + h2s + "\n" + faq_html + "\n" + schema_html

payload = {"article": {"id": ART,
    "title": "Creatures of the Night Wallpaper by Zak and Fox",
    "body_html": new_body,
    "metafields": [
      {"namespace": "global", "key": "title_tag",
       "value": "Creatures of the Night Wallpaper by Zak and Fox | Designer Wallcoverings",
       "type": "single_line_text_field"},
      {"namespace": "global", "key": "description_tag",
       "value": "Creatures of the Night by Zak and Fox is a dark, nocturnal luxury wallcovering for dramatic rooms. Order up to 10 free samples and get trade pricing.",
       "type": "single_line_text_field"},
    ]}}

res = put(f"blogs/{BLOG}/articles/{ART}.json", payload)['article']
print("PUBLISHED OK  updated_at:", res.get('updated_at'))
print("title  :", res.get('title'))
print("body   :", len(res.get('body_html') or ''), "chars (was", len(orig_body), ")")
nb = res.get('body_html') or ''
print("images kept:", len(re.findall(r'<img', nb)), "| poem kept:", 'midnight' in nb.lower(),
      "| faq schema:", 'FAQPage' in nb)