#!/usr/bin/env python3 """ Download all product images from Deal Plus Tech """ import requests import os from urllib.parse import urljoin, urlparse import re BASE_URL = "https://www.dealplustech.co.th" # All products from the original website PRODUCTS = [ # Pipes ("ท่อ-ppr-thai-ppr", "ท่อ PPR – Thai PPR", "thai-ppr"), ("ท่อพีพีอาร์ตราช้าง", "ท่อ PPR – ตราช้าง (SCG)", "ppr-elephant"), ("pp-r-pp-rct-poloplast", "PP-R / PP-RCT POLOPLAST", "poloplast"), ("ท่อhdpe", "ท่อ HDPE ราคาโรงงาน", "hdpe"), ("ท่อ-upvc", "ท่อ UPVC", "upvc"), ("ท่อและข้อต่อpvc", "ท่อ PVC และข้อต่อ", "pvc"), ("ท่อไซเลอร์", "ท่อไซเลอร์ | Syler", "syler"), ("ท่อระบายน้ำ-3-ชั้น-ไซเลนท", "ท่อระบายน้ำ 3 ชั้น ไซเลนท์ | XYLENT", "xylent"), # Couplings ("dukelarrsen", "DUKELARRSEN", "dukelarrsen"), ("groove-coupling", "กรู๊ฟท่อ (Groove Coupling)", "groove"), ("pipe-coupling", "ข้อต่อท่อ (Pipe Coupling)", "pipe-coupling"), ("เม็กกรู๊ฟ-คับปลิ้ง", "เม็กกรู๊ฟ คับปลิ้ง", "mech"), # Valves & Pumps ("วาล์ว-valve", "วาล์ว | Valve", "valve"), ("water-pump", "ปั๊มพ์น้ำ (Water Pump)", "water-pump"), ("water-treatment", "ระบบกรองน้ำดี (Water Treatment)", "water-treatment"), # HVAC ("grilles", "กริลแอร์พลาสติก | Grilles plastic", "grilles"), ("durgo-avvs", "ระบบวาล์วเติมอากาศ DURGO AVVs", "durgo"), ("realflex", "Realflex", "realflex"), ("ท่อระบายน้ำ-3-ชั้น-ไซเลนท", "ท่อระบายน้ำ 3 ชั้น ไซเลนท์", "xylent-2"), ("หัวจ่ายแอร์-ball-jet", "หัวจ่ายแอร์ | BALL JET", "ball-jet"), # Insulation ("เทอร์โมเบรค-thermobreak", "เทอร์โมเบรค (Thermobreak)", "thermobreak"), ("ฉนวนหุ้มท่อ-pipe-insulation", "ฉนวนหุ้มท่อ | Pipe Insulation", "insulation"), # Hangers & Clamps ("สปริทริงแฮงเกอร์-sr19-adjustable-split-ring-hanger", "สปริทริงแฮงเกอร์ (SR19)", "sr19"), ("เควิสแฮงเกอร์", "เควิสแฮงเกอร์", "clevis"), ("แคล้มประกับ", "แคล้มประกับ", "conduit-clamp"), ("แคล้มฟันจระเข้-beam-clamp", "แคล้มฟันจระเข้", "beam-clamp"), ("แคล้มหยดน้ำ-adjustable-band-hanger", "แคล้มหยดน้ำ", "band-hanger"), ("แคล้มเลเวล-level-clamp", "แคล้มเลเวล", "level-clamp"), # Bolts ("เจโบลท์-แอลโบลท์", "เจโบลท์ แอลโบลท์", "j-bolt"), ("ยูโบลท์-u-bolt", "ยูโบลท์", "u-bolt"), ("ยูโบลท์-ประกับ-u-bolt-clamp", "ยูโบลท์ + ประกับ", "u-bolt-clamp"), ("ยูโบลท์เหล็กแผ่น-ยูแบน-strap", "ยูโบลท์เหล็กแผ่น (ยูแบน)", "strap-u-bolt"), ("สตัดเกลียวตลอด-เหล็ก-threaded-rod", "สตัดเกลียวตลอด", "threaded-rod"), # Fasteners ("น็อต-แหวน-สกรู", "น็อต แหวน สกรู", "nuts-bolts"), ("พุกต่างๆ", "พุกต่างๆ", "anchors"), ("พุกเหล็ก-sleeve-anchor-bolt", "พุกเหล็ก", "sleeve-anchor"), # Welding Machines ("เครื่องเชื่อม-hdpe", "เครื่องเชื่อม HDPE", "hdpe-welding"), ("เครื่องเชื่อมท่อพีพีอาร์", "เครื่องเชื่อมท่อพีพีอาร์", "ppr-welding"), # Fencing ("ระบบรั้วไวน์แมน-vineman", "ระบบรั้วไวน์แมน", "vineman"), ("รั้วเทวดา", "รั้วเทวดา", "tevada"), # Fire Equipment ("อุปกรณ์ดับเพลิง", "อุปกรณ์ดับเพลิง", "extinguishers"), ] def download_image(url, output_path): """Download image from URL""" try: headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', } response = requests.get(url, headers=headers, timeout=30, stream=True) response.raise_for_status() with open(output_path, 'wb') as f: for chunk in response.iter_content(8192): f.write(chunk) return True except Exception as e: print(f" ❌ Failed: {e}") return False def download_product_images(): """Download all product images""" output_dir = "/Users/kunthawatgreethong/Gitea/dealplustech/public/images/2021/03" os.makedirs(output_dir, exist_ok=True) downloaded = [] failed = [] for slug, name, short_name in PRODUCTS: print(f"\n📦 {name}") # Try different image naming patterns image_patterns = [ f"{short_name}_000C.jpg", f"{short_name}_000C-768x1024.jpg", f"{short_name}-cover_000C.jpg", f"{short_name}_cover_000C-768x1024.jpg", ] found = False for pattern in image_patterns: image_url = f"{BASE_URL}/wp-content/uploads/2021/03/{pattern}" output_path = os.path.join(output_dir, pattern) if os.path.exists(output_path): print(f" ✓ Already exists: {pattern}") found = True downloaded.append((name, pattern)) break print(f" Downloading: {pattern}...") if download_image(image_url, output_path): print(f" ✓ Downloaded: {pattern}") found = True downloaded.append((name, pattern)) break if not found: print(f" ⚠ No image found for {name}") failed.append(name) # Be polite import time time.sleep(0.3) # Summary print(f"\n{'='*60}") print(f"✅ Downloaded: {len(downloaded)} images") print(f"❌ Failed: {len(failed)} images") if failed: print("\nFailed products:") for name in failed: print(f" - {name}") return downloaded, failed if __name__ == '__main__': print("=== Downloading Product Images ===\n") download_product_images()