← back to Designer Wallcoverings

onboarding/sangetsu-lilycolor/scripts/local-reenrich.sh

51 lines

#!/bin/bash
# Re-enrich the error/unusable SKUs from the LOCAL image cache (stable SSD),
# not flaky Henry. Seeds off SUCCESSFUL rows so only error SKUs are redone.
# Remerges (last-wins) into final. Local, $0, reversible (JSONL only).
set -u
PROJ="$HOME/Projects/Designer-Wallcoverings/onboarding/sangetsu-lilycolor"; cd "$PROJ" || exit 1
ST="$PROJ/staging"; CACHE="$PROJ/.image-cache/lily"
FINAL="$ST/enrichment-full-063026A.final.jsonl"
GOOD="$ST/enrichment-full-063026A.good-seed2.jsonl"
REC="$ST/enrichment-full-063026A.local-recovery.jsonl"
log(){ echo "[localre $(date '+%H:%M:%S')] $*" >> "$ST/enrich-localre.log"; }

# good-seed2 = final rows WITHOUT error and not usable:false
python3 - "$FINAL" "$GOOD" <<'PY' 2>> "$ST/enrich-localre.log"
import json,sys
src,good=sys.argv[1],sys.argv[2]; bad=0
with open(good,"w") as g:
    for line in open(src):
        line=line.strip()
        if not line: continue
        try:o=json.loads(line)
        except:continue
        if o.get("error") or o.get("usable") is False: bad+=1; continue
        g.write(json.dumps(o)+"\n")
print(f"[scan] good={sum(1 for _ in open(good))} to-retry={bad}")
PY
log "re-enrich from LOCAL cache $CACHE (seeded off good rows)"
ENRICH_HENRY_DIR="$CACHE" ENRICH_SHARD_COUNT=1 ENRICH_OLLAMA_URL=http://127.0.0.1:11434 \
ENRICH_DONE_SEEDS="$GOOD" python3 -u scripts/enrich-full.py "$REC" >> "$ST/enrich-localre.log" 2>&1
log "recovery run done. rec rows=$(wc -l < "$REC" 2>/dev/null)"

python3 - "$GOOD" "$REC" "$FINAL" <<'PY' 2>> "$ST/enrich-localre.log"
import json,sys
srcs,final=sys.argv[1:-1],sys.argv[-1]; by={}
for p in srcs:
    try:
        for line in open(p):
            line=line.strip()
            if not line: continue
            try:o=json.loads(line)
            except:continue
            s=o.get("sku")
            if s: by[s]=o
    except FileNotFoundError: pass
ok=sum(1 for o in by.values() if not o.get("error") and o.get("usable") is not False)
with open(final,"w") as f:
    for s in sorted(by): f.write(json.dumps(by[s])+"\n")
print(f"[remerge] final={len(by)} ok={ok} err={len(by)-ok}")
PY
log "REMERGE done. final=$(wc -l < "$FINAL") rows"; touch "$ST/LOCALRE-DONE"; log "ALL DONE"