← back to Dw Vendor Microsites
merge-work/merge-house.sh
91 lines
#!/usr/bin/env bash
# merge-house.sh <house_key>
#
# Re-exports each source vendor's catalog with the CURRENT fixed export-catalog.sh
# (scrubbing to the HOUSE name with the COMBINED banned set), concatenates them into
# one deduped combined staging JSONL, and leak-scans the result.
#
# Houses:
# malibu_house : malibu + brewster_york -> "Malibu Wallpaper"
# phillipe_romano_house: justindavid + phillipe_romano + relativity_textiles + twil_karin -> "Phillipe Romano"
# hollywood_house : command54 + hollywood -> "Hollywood Wallcoverings"
#
# LOCAL ONLY. No deploy.
set -euo pipefail
HK="${1:?usage: merge-house.sh <house_key>}"
REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$REPO"
EXPORT="$REPO/lib/export-catalog.sh"
case "$HK" in
malibu_house)
HOUSE="Malibu Wallpaper"
SOURCES=("malibu:malibu_catalog" "brewster_york:brewster_catalog")
BANNED=("Brewster & York" "Brewster" "York" "Chesapeake" "Seabrook" "NextWall" "WallQuest")
;;
phillipe_romano_house)
HOUSE="Phillipe Romano"
SOURCES=("justindavid:justindavid_catalog" "phillipe_romano:phillipe_romano_catalog" "relativity_textiles:relativity_textiles_catalog" "twil_karin:twil_karin_catalog")
BANNED=("York/Brewster (Phillipe Romano source)" "Relativity Textiles" "Justin David" "TWIL Karin" "TWIL" "Command54" "York" "Brewster")
;;
hollywood_house)
HOUSE="Hollywood Wallcoverings"
SOURCES=("command54:command54_catalog" "hollywood:hollywood_catalog")
BANNED=("Command54" "Momentum" "WallQuest" "Chesapeake" "Seabrook" "NextWall" "Brewster" "York")
;;
*) echo "unknown house_key: $HK" >&2; exit 1;;
esac
echo "== merge $HK -> HOUSE='$HOUSE' banned=[${BANNED[*]}] =="
STAGE_FILES=()
for pair in "${SOURCES[@]}"; do
vcode="${pair%%:*}"; ctable="${pair##*:}"
out="$REPO/staging/${vcode}.jsonl"
echo "-- re-export $vcode ($ctable) with fixed scrub -> $out"
n="$(HOUSE="$HOUSE" bash "$EXPORT" "$ctable" "$out" "${BANNED[@]}")"
echo " exported $n rows"
STAGE_FILES+=("$out")
done
# ---- concatenate + dedup (exact-duplicate lines AND same mfr_sku+color_name) ----
COMBINED="$REPO/staging/${HK}.jsonl"
echo "-- concat + dedup -> $COMBINED"
python3 - "$COMBINED" "${STAGE_FILES[@]}" <<'PY'
import sys, json
out_path = sys.argv[1]
files = sys.argv[2:]
seen_line = set()
seen_key = set()
kept = 0; dup_line = 0; dup_key = 0
with open(out_path, 'w') as fout:
for f in files:
with open(f) as fin:
for line in fin:
line = line.rstrip('\n')
if not line.strip():
continue
# exact-duplicate line
if line in seen_line:
dup_line += 1
continue
seen_line.add(line)
# same mfr_sku + color_name dedup (only when mfr_sku present)
try:
r = json.loads(line)
except Exception:
r = None
if r is not None:
mk = (r.get('mfr_sku') or r.get('sku') or '')
ck = (r.get('color_name') or '')
if mk:
key = (str(mk).strip().lower(), str(ck).strip().lower())
if key in seen_key:
dup_key += 1
continue
seen_key.add(key)
fout.write(line + '\n')
kept += 1
print(json.dumps({"kept": kept, "dup_exact_line": dup_line, "dup_mfr_color": dup_key, "total_dedup": dup_line + dup_key}))
PY