← back to Japan Enrich
scripts/get-all-live.sh
54 lines
#!/usr/bin/env bash
# Push ALL new Sangetsu patterns (Thailand-uncategorized 'storeapi-new' + Singapore 'gg-sg-new')
# to the LIVE japan viewer by APPEND — never overwrites (live has more colorways for the original
# 623). Idempotent (skips source_urls already live). Merges the brand map additively so the new
# patterns' distributors land. Run under Steve AFTER the Singapore brand scrape finishes.
# bash ~/Projects/japan-enrich/scripts/get-all-live.sh
set -euo pipefail
cd "$(dirname "$0")/.."
# 1) extract the new patterns + their brand entries locally
python3 - <<'PY'
import json
bm=json.load(open('staging/sangetsu-brands.json'))
recs=[]; brands={}
for l in open('staging/sangetsu-staging.jsonl'):
l=l.strip()
if not l: continue
r=json.loads(l)
if r.get('status') in ('storeapi-new','gg-sg-new'):
recs.append(json.dumps(r,ensure_ascii=False)); u=r['source_url']
brands[u]=bm.get(u,{'distributor':r.get('distributor'),'slug':None})
open('staging/sangetsu-newpatterns.jsonl','w').write('\n'.join(recs)+('\n' if recs else ''))
json.dump(brands,open('staging/sangetsu-brands-new.json','w'),ensure_ascii=False)
blank=sum(1 for u,v in brands.items() if not v.get('distributor'))
print(f'{len(recs)} new patterns, {len(brands)} brand entries ({blank} still blank)')
PY
# 2) push the small patch files
rsync -avz staging/sangetsu-newpatterns.jsonl staging/sangetsu-brands-new.json \
root@45.61.58.125:/root/Projects/japan-staging-viewer/staging/
# 3) idempotent append + additive brand merge on the server, then reload
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-newpatterns.jsonl'):
l=l.strip()
if not l: continue
r=json.loads(l); s=slug(r.get('source_url',''))
if s not in have: out.write(l+'\n'); have.add(s); added+=1
bm=json.load(open('sangetsu-brands.json')); new=json.load(open('sangetsu-brands-new.json'))
bm.update(new)
json.dump(bm,open('sangetsu-brands.json','w'),ensure_ascii=False,indent=0)
print(f'appended {added} new patterns to LIVE staging; brand map now {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 | python3 -c 'import sys,json;print(json.load(sys.stdin)[\"total\"])'"