Files
mozimo.in/scripts/fetch-assets.py
T
tanshu 328a1a23e0 Agent skills
Prettier
eslint
shopify
2026-09-06 06:38:04 +00:00

72 lines
3.2 KiB
Python

#!/usr/bin/env python3
"""Download real product imagery from Mozimo's Shopify CDN + tempering video + Fraunces font."""
import json, os, re, subprocess, sys
ROOT = "/home/tanshu/programming/mozimo/mozimo-chatgpt"
PUB = os.path.join(ROOT, "public")
os.makedirs(f"{PUB}/products", exist_ok=True)
os.makedirs(f"{PUB}/videos", exist_ok=True)
UA = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0 Safari/537.36"
def fetch(url, out, extra_headers=None):
if os.path.exists(out) and os.path.getsize(out) > 1000:
return True
cmd = ["curl", "-sL", "--max-time", "60", "-A", UA, "-o", out, url]
r = subprocess.run(cmd, capture_output=True)
ok = r.returncode == 0 and os.path.exists(out) and os.path.getsize(out) > 1000
if not ok:
print(f" !! FAILED {url[:90]} -> {out}")
if os.path.exists(out): os.remove(out)
return ok
# ---------- 1. Products ----------
print("== products ==")
r = subprocess.run(["curl", "-sL", "--max-time", "60", "-A", UA,
"https://shop.mozimo.in/products.json?limit=250"], capture_output=True)
d = json.loads(r.stdout)
products = d.get("products", [])
manifest = []
seen_files = set()
for p in products:
imgs = p.get("images") or []
if not imgs:
continue
src = imgs[0]["src"]
base = src.split("?")[0].split("/")[-1]
slug = re.sub(r"[^a-z0-9]+", "-", base.lower()).strip("-")
slug = re.sub(r"-jpg$", "", slug)
ext = ".jpg" if base.lower().endswith((".jpg", ".jpeg")) else ".png"
fname = f"{slug}{ext}"
if fname in seen_files:
# dedupe identical basenames (same photo reused)
manifest.append({"handle": p["handle"], "title": p["title"], "file": fname})
continue
seen_files.add(fname)
url = src + ("&" if "?" in src else "?") + "width=1100&quality=82"
if fetch(url, f"{PUB}/products/{fname}"):
manifest.append({"handle": p["handle"], "title": p["title"], "file": fname, "price": (p.get("variants") or [{}])[0].get("price")})
print(f" ok {fname}")
json.dump(manifest, open(f"{ROOT}/scripts/products-manifest.json", "w"), indent=1)
print(f"total products with images: {len(manifest)}")
# ---------- 2. Video ----------
print("== video ==")
fetch("https://qa-dugout.s3.ap-south-1.amazonaws.com/testing/v1.mp4", f"{PUB}/videos/tempering.mp4")
print("video size:", os.path.getsize(f"{PUB}/videos/tempering.mp4") if os.path.exists(f"{PUB}/videos/tempering.mp4") else "MISSING")
# ---------- 3. Fraunces (variable, latin) ----------
print("== fonts ==")
css_url = "https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,300..700;1,9..144,300..700&display=swap"
r = subprocess.run(["curl", "-sL", "-A", UA, css_url], capture_output=True, text=True)
css = r.stdout
blocks = re.findall(r"/\* latin \*/\s*@font-face\s*\{([^}]+)\}", css)
for block in blocks:
style = re.search(r"font-style:\s*(\w+)", block).group(1)
url = re.search(r"src:\s*url\((https://[^)]+)\)", block).group(1)
name = f"fraunces-latin-{'italic' if style == 'italic' else 'normal'}.woff2"
if fetch(url, f"{PUB}/fonts/{name}"):
print(f" ok {name} ({os.path.getsize(f'{PUB}/fonts/{name}')} bytes)")
print("DONE")