import html import json import re import subprocess import urllib.parse from pathlib import Path OUT = Path(__file__).resolve().parent OUT.mkdir(parents=True, exist_ok=True) AGENT = "PerfectCoffeeAssetResearch/1.0" COMMONS = { "milk_bottle": "Bottle of milk.jpg", "croissant": "Croissant 1.jpg", "cake_slice": "Slice of chocolate cake.jpg", "cream_toast": "Buttered toast.jpg", } def fetch(url): return subprocess.check_output( ["curl", "-sSL", "--fail", "--max-time", "45", "-A", AGENT, url] ) sources = [] for name, title in COMMONS.items(): query = urllib.parse.urlencode({ "action": "query", "format": "json", "prop": "imageinfo", "iiprop": "url|extmetadata", "iiurlwidth": "1000", "titles": "File:" + title, }) data = json.loads(fetch("https://commons.wikimedia.org/w/api.php?" + query)) info = next(iter(data["query"]["pages"].values()))["imageinfo"][0] metadata = info["extmetadata"] target = OUT / (name + ".jpg") target.write_bytes(fetch(info["thumburl"])) sources.append({ "asset": name, "file": target.name, "title": info.get("descriptionurl", title).rsplit("/", 1)[-1], "page_url": info["descriptionurl"], "image_url": info["thumburl"], "creator": html.unescape(re.sub(r"<[^>]+>", "", metadata.get("Artist", {}).get("value", ""))), "license": metadata.get("LicenseShortName", {}).get("value"), "license_url": metadata.get("LicenseUrl", {}).get("value"), "usage": "Visual shape reference only; no photographic texture is used in the models.", }) product_references = [ { "asset": "milk_2l", "file": "milk_2l_woolworths.png", "title": "Woolworths Full Cream Milk 2L", "page_url": "https://www.woolworths.com.au/shop/productdetails/888137/woolworths-full-cream-milk", "image_url": "https://www.woolworths.com.au/shop/productdetails/888137/woolworths-full-cream-milk", "creator": "Woolworths", "license": "Product photo; internal visual reference only", "usage": "User-specified rectangular body, chamfered base, tapered shoulders and integral arched handle opening. No label used.", "local_capture": True, }, { "asset": "milk_2l_supplier_previous", "file": "milk_2l_supplier.jpg", "title": "2 Litre 2000ml HDPE Plastic Bottle for Milk Juice with Handle", "page_url": "https://zhenghaoplastic.en.made-in-china.com/product/lmCRJEMTawkb/China-2-Litre-2000ml-HDPE-Plastic-Bottle-for-Milk-Juice-Food-Grade-Plastic-Bottle-with-Handle.html", "image_url": "https://image.made-in-china.com/2f0j00tvhbymoGfOca/2-Litre-2000ml-HDPE-Plastic-Bottle-for-Milk-Juice-Food-Grade-Plastic-Bottle-with-Handle.jpg", "creator": "Shenzhen Zhenghao Plastic & Mold Co., Ltd", "license": "Supplier product photo; internal visual reference only", "usage": "2L capacity, HDPE body and integral handle. No supplier branding or labels used.", }, { "asset": "orange_juice_2l", "file": "orange_juice_2l_product.webp", "title": "Rita NFC Orange Juice Drink 2L PET Bottle", "page_url": "https://ritabeverage.com/products/fruit-drink/rita-nfc-orange-juice-drink-2l-pet-bottle", "image_url": "https://ritabeverage.com/media/zoo/images/Rita_NFC_Orange_Juice_Drink_2L_PET_Bottle_9007b71ded187b8476887cf78c0d5446.webp", "creator": "Rita Food & Drink Co., Ltd", "license": "Supplier product photo; internal visual reference only", "usage": "2L clear PET silhouette, neck and screw cap only; no branding or labels used.", }, ] for source in product_references: if source.get("local_capture"): assert (OUT / source["file"]).is_file(), "Supply the saved product-page reference crop" else: (OUT / source["file"]).write_bytes(fetch(source["image_url"])) sources.append(source) (OUT / "sources.json").write_text( json.dumps({ "accessed": "2026-11-15", "notes": "References inform proportions and recognizable features. Models are original low-poly geometry, without brand graphics or packaging labels.", "references": sources, }, ensure_ascii=False, indent=2) + "\n", encoding="utf-8", ) print(f"Saved {len(sources)} reference photos to {OUT}")