← back to Dw Marketing Viewer
site-deploy/_remote-edit-chips.py
37 lines
#!/usr/bin/env python3
# Runs ON the Kamatera server. Adds the 76 AI-design collections as browse chips
# in loadFacets() on wallpapersback.com (DTD verdict A). Backup-safe, idempotent.
import time
idx = "/root/public-projects/wallpapersback/public/index.html"
s = open(idx, encoding="utf-8").read()
ts = int(time.time())
if "/api/categories" in s:
print(" · design-collection chips already present — skipping")
raise SystemExit(0)
old = (" const _chipEntries = Object.entries(f.aesthetics).sort((a,b) => b[1] - a[1]);\n"
" const _CHIP_VISIBLE = 8;")
new = (" const _chipEntries = Object.entries(f.aesthetics).sort((a,b) => b[1] - a[1]);\n"
" // DTD verdict A 2026-06-23: append the AI-design collections (de-duped vs rails,\n"
" // colorway combos excluded) so they're browsable under \"Show all\".\n"
" try {\n"
" const _cr = await fetch('/api/categories');\n"
" if (_cr.ok) {\n"
" const _have = new Set(_chipEntries.map(([k]) => k.toLowerCase()));\n"
" (((await _cr.json()).items) || [])\n"
" .filter(c => c.category && c.count > 0 && !c.category.includes(' · ') && !_have.has(c.category.toLowerCase()))\n"
" .forEach(c => { _have.add(c.category.toLowerCase()); _chipEntries.push([c.category, c.count]); });\n"
" }\n"
" } catch (e) { console.error('loadCategories failed:', e); }\n"
" const _CHIP_VISIBLE = 8;")
if old not in s:
print(" ! ERROR: loadFacets anchor not found — aborting, NO changes")
raise SystemExit(1)
open(idx + ".bak-collections-chips-%d" % ts, "w", encoding="utf-8").write(s)
s = s.replace(old, new, 1)
open(idx, "w", encoding="utf-8").write(s)
print(" ✓ design-collection chips added to loadFacets (backup .bak-collections-chips-%d)" % ts)