← back to Hollywood Price 2026
build_plan_correct.py
64 lines
#!/usr/bin/env python3
"""Build the CORRECT Hollywood pricing plan.
Join: Shopify sku-base (variant sku minus -sample) == staged `mfr` (verified ==
manufacturer_sku == staged col3; staged hw matches live Momentum x1.448).
Price = staged `hw`. Unit = staged `unit`. NEVER use the DWHW2 dw_sku (garbage).
Sellable SKU = sku-base + unit-suffix. Output plan_correct.csv. $0."""
import sys
import os
import json
import csv
import collections
sys.path.insert(0, "lib")
from shopify import gql
HI = os.path.expanduser("~/Projects/hollywood-import")
OUT = "plan_correct.csv"
def main():
staged = {str(r["mfr"]).strip(): r for r in json.load(open(HI + "/mom-col3-staged.json")) if r.get("mfr")}
Q = """query($q:String!,$after:String){ products(first:200, after:$after, query:$q){
pageInfo{hasNextPage endCursor}
edges{ node{ id legacyResourceId handle title
variants(first:5){ edges{ node{ sku } } } } } } }"""
prods, cur = [], None
while True:
d = gql(Q, {"q": "vendor:'Hollywood Wallcoverings' status:active tag:Needs-Price", "after": cur})
p = d["products"]; prods += [e["node"] for e in p["edges"]]
if not p["pageInfo"]["hasNextPage"]:
break
cur = p["pageInfo"]["endCursor"]
def base(n):
for e in n["variants"]["edges"]:
sk = (e["node"]["sku"] or "")
if sk.lower().endswith("-sample"):
return sk[:-len("-sample")]
return None
rows = []
for n in prods:
sb = base(n)
if not sb or sb not in staged:
continue
st = staged[sb]
hw = st.get("hw")
if not hw or float(hw) <= 0:
continue
rows.append({
"gid": n["id"], "product_id": n["legacyResourceId"], "handle": n["handle"],
"title": n["title"], "sku_base": sb, "unit": (st.get("unit") or "").upper(),
"hw": hw, "list": st.get("list"), "mom_pattern": st.get("momPattern"), "col3": st.get("col3"),
})
with open(OUT, "w", newline="") as f:
w = csv.DictWriter(f, fieldnames=list(rows[0].keys())); w.writeheader(); w.writerows(rows)
print(f"PLAN_CORRECT: {len(rows)} priceable -> {OUT}")
print(" unit dist:", dict(collections.Counter(r["unit"] for r in rows)))
hws = sorted(float(r["hw"]) for r in rows)
print(f" hw range: ${hws[0]:.2f}-${hws[-1]:.2f} median ${hws[len(hws)//2]:.2f}")
if __name__ == "__main__":
main()