← back to Japan Enrich

scripts/append-9-to-live.sh

53 lines

#!/usr/bin/env bash
# Add ONLY the 9 new Sangetsu wallcovering patterns to the LIVE japan viewer's staging,
# by APPEND (never overwrite — live has 18,272 colorways vs local 13,556). Idempotent:
# skips any pattern whose source_url is already present. Merges brand entries additively.
# Run under Steve:  bash ~/Projects/japan-enrich/scripts/append-9-to-live.sh
set -euo pipefail
cd "$(dirname "$0")/.."

# 1) extract the 9 new records + their brand entries locally
python3 - <<'PY'
import json
recs=[]; brands={}
bm=json.load(open('staging/sangetsu-brands.json'))
for l in open('staging/sangetsu-staging.jsonl'):
    l=l.strip()
    if not l: continue
    r=json.loads(l)
    if r.get('status')=='storeapi-new':
        recs.append(l); u=r['source_url']
        brands[u]=bm.get(u,{'distributor':r.get('distributor'),'slug':None})
open('staging/sangetsu-new9.jsonl','w').write('\n'.join(recs)+('\n' if recs else ''))
json.dump(brands,open('staging/sangetsu-brands-new9.json','w'),ensure_ascii=False)
print(f'extracted {len(recs)} records + {len(brands)} brand entries')
PY

# 2) push the small patch files
rsync -avz staging/sangetsu-new9.jsonl staging/sangetsu-brands-new9.json \
  root@45.61.58.125:/root/Projects/japan-staging-viewer/staging/

# 3) apply on the server: idempotent append + additive brand merge, then reload the viewer
ssh root@45.61.58.125 bash -s <<'REMOTE'
cd /root/Projects/japan-staging-viewer/staging
python3 - <<'PY'
import json
def slug(u): return (u or '').rstrip('/').split('/')[-1].lower()
have={slug(json.loads(l).get('source_url','')) for l in open('sangetsu-staging.jsonl') if l.strip()}
added=0
with open('sangetsu-staging.jsonl','a') as out:
    for l in open('sangetsu-new9.jsonl'):
        l=l.strip()
        if not l: continue
        r=json.loads(l)
        if slug(r.get('source_url','')) not in have:
            out.write(l+'\n'); added+=1
bm=json.load(open('sangetsu-brands.json')); new=json.load(open('sangetsu-brands-new9.json'))
for k,v in new.items(): bm.setdefault(k,v)
json.dump(bm,open('sangetsu-brands.json','w'),ensure_ascii=False,indent=0)
print(f'appended {added} new patterns to LIVE staging; brand map merged ({len(bm)} keys)')
PY
pm2 restart japan-viewer >/dev/null 2>&1 && echo "viewer restarted"
REMOTE
echo "done — verify: curl -su admin:DW2024! https://japan.designerwallcoverings.com/api/products | grep -c storeapi"