[object Object]

← back to Carnegie Import

chore: lint (3 autofix), refactor, untrack images, v0.1.0 (session close)

f731bfe293c82063648db66dfdea9f8dd4e76798 · 2026-07-22 11:02:55 -0700 · Steve Abrams

Files touched

Diff

commit f731bfe293c82063648db66dfdea9f8dd4e76798
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Wed Jul 22 11:02:55 2026 -0700

    chore: lint (3 autofix), refactor, untrack images, v0.1.0 (session close)
---
 .gitignore         |  4 ++++
 VERSION            |  1 +
 enrich_palette.py  |  4 ++--
 publish_shopify.py |  5 +++--
 scrape_carnegie.py | 16 +++++++---------
 5 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/.gitignore b/.gitignore
index 6b393c0..f55fc95 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,7 @@ tmp/
 dist/
 build/
 __pycache__/
+
+images/
+enrich.log
+*.raw.json
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..6e8bf73
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.1.0
diff --git a/enrich_palette.py b/enrich_palette.py
index f4c9f98..5f723fc 100644
--- a/enrich_palette.py
+++ b/enrich_palette.py
@@ -4,7 +4,7 @@ download swatch image local, extract full palette (hex + coverage %), nearest
 colorway name, primary hex + bucket, color_tags; then set activation_pass per
 the 5-field + full-palette gate. Caches by image_url to avoid redundant fetches.
 """
-import io, json, os, re, subprocess, sys, time, urllib.request
+import io, json, os, subprocess, sys, time, urllib.request
 from PIL import Image
 
 DSN = "host=/tmp dbname=dw_unified"
@@ -103,7 +103,7 @@ def main():
             phex=pal[0]["hex"];pbucket=pal[0]["bucket"]
             buf.append((rid,pal,ctags,phex,pbucket,os.path.basename(lp)))
             done+=1
-        except Exception as e:
+        except Exception:
             buf.append((rid,None,None,None,None,None));fail+=1
         if len(buf)>=100:
             flush(buf);buf=[]
diff --git a/publish_shopify.py b/publish_shopify.py
index bae7395..e6daf5e 100644
--- a/publish_shopify.py
+++ b/publish_shopify.py
@@ -16,8 +16,9 @@ import argparse, base64, json, os, subprocess, sys, time, urllib.request
 DSN = "host=/tmp dbname=dw_unified"
 UA  = "Mozilla/5.0"
 def env(k):
-    for line in open(os.path.expanduser("~/Projects/secrets-manager/.env")):
-        if line.startswith(k+"="): return line.split("=",1)[1].strip()
+    with open(os.path.expanduser("~/Projects/secrets-manager/.env")) as f:
+        for line in f:
+            if line.startswith(k + "="): return line.split("=", 1)[1].strip()
     return None
 TOKEN = env("SHOPIFY_ADMIN_TOKEN")
 STORE = "designer-laboratory-sandbox.myshopify.com"
diff --git a/scrape_carnegie.py b/scrape_carnegie.py
index 4c4e65e..6a62227 100644
--- a/scrape_carnegie.py
+++ b/scrape_carnegie.py
@@ -36,7 +36,7 @@ def gql(page, size=50, retries=4):
             if "errors" in d and not d.get("data"):
                 raise RuntimeError(d["errors"])
             return d["data"]["products"]
-        except Exception as e:
+        except Exception:
             if a == retries - 1:
                 raise
             time.sleep(2 * (a + 1))
@@ -92,7 +92,7 @@ def main():
         cats = [c["name"] for c in (it.get("categories") or [])]
         pr = (((it.get("price_range") or {}).get("minimum_price") or {}).get("regular_price") or {})
         price, cur = pr.get("value"), pr.get("currency")
-        desc_html = ((it.get("description") or {}) or {}).get("html") or ((it.get("short_description") or {}) or {}).get("html")
+        desc_html = (it.get("description") or {}).get("html") or (it.get("short_description") or {}).get("html")
         desc_txt = re.sub(r"<[^>]+>", "", desc_html or "").strip() or None
         gallery = [g["url"] for g in (it.get("media_gallery") or [])]
         purl = "https://carnegiefabrics.com/" + (it.get("url_key") or "")
@@ -107,7 +107,7 @@ def main():
                 categories=cats, body_html=desc_html, description_text=desc_txt,
                 price=price, currency=cur,
                 all_images=([cimg] if cimg else []) + gallery,
-                image_url=(cimg or ((it.get("image") or {}) or {}).get("url")),
+                image_url=(cimg or (it.get("image") or {}).get("url")),
                 product_url=purl, is_variant=is_var,
                 raw={"sku": it.get("sku"), "typename": it.get("__typename")})
 
@@ -135,17 +135,15 @@ def main():
             "product_url","is_variant","raw"]
     def val(r, c):
         v = r[c]
-        if c in ("categories","all_images"):
+        if c in ("categories", "all_images"):
             return pgarr(v)
-        if c == "raw":
-            return sqlq(v)
         return sqlq(v)
 
     # batch inserts with upsert (NEVER-DUPLICATE)
-    B = 200
+    BATCH = 200
     inserted = 0
-    for i in range(0, len(uniq), B):
-        chunk = uniq[i:i+B]
+    for i in range(0, len(uniq), BATCH):
+        chunk = uniq[i:i+BATCH]
         vals = ",\n".join("(" + ",".join(val(r, c) for c in cols) + ")" for r in chunk)
         sql = (f"INSERT INTO carnegie_catalog ({','.join(cols)}) VALUES\n{vals}\n"
                "ON CONFLICT (mfr_sku) DO UPDATE SET "

← 084d704 publish_shopify: add paginated dedup guard so re-runs skip a  ·  back to Carnegie Import  ·  (newest)