644 lines
28 KiB
Python
644 lines
28 KiB
Python
"""
|
|
Script to populate 40 Cashify refurbished products with variants, images, prices in INR into PostgreSQL DB.
|
|
"""
|
|
import ulid
|
|
import re
|
|
from decimal import Decimal
|
|
import app.models.db_base
|
|
from app.core.database.db_session import SessionLocal
|
|
from app.models.ProductModel import Product, ProductVariant, ProductImage
|
|
from app.models.BrandModel import Brand
|
|
from app.models.CategoryModel import Category
|
|
|
|
db = SessionLocal()
|
|
|
|
# Ensure brands
|
|
brand_names = ["Apple", "Samsung", "OnePlus", "Xiaomi", "Google", "Sony", "Dell", "Bose"]
|
|
brand_map = {}
|
|
for name in brand_names:
|
|
slug = name.lower()
|
|
b = db.query(Brand).filter(Brand.slug == slug).first()
|
|
if not b:
|
|
b = Brand(
|
|
brand_id=str(ulid.ULID()),
|
|
name=name,
|
|
slug=slug,
|
|
is_active=True
|
|
)
|
|
db.add(b)
|
|
db.commit()
|
|
db.refresh(b)
|
|
brand_map[name] = b.brand_id
|
|
|
|
# Ensure categories
|
|
cat_names = {
|
|
"Smartphones": "smartphones",
|
|
"Laptops": "laptops",
|
|
"Tablets": "tablets",
|
|
"Gaming Consoles": "gaming-consoles",
|
|
"Audio & Headphones": "audio-headphones",
|
|
"Smartwatches": "smartwatches"
|
|
}
|
|
cat_map = {}
|
|
for name, slug in cat_names.items():
|
|
c = db.query(Category).filter(Category.slug == slug).first()
|
|
if not c:
|
|
c = Category(
|
|
category_id=str(ulid.ULID()),
|
|
name=name,
|
|
slug=slug,
|
|
is_active=True
|
|
)
|
|
db.add(c)
|
|
db.commit()
|
|
db.refresh(c)
|
|
cat_map[name] = c.category_id
|
|
|
|
# 40 Products Data
|
|
PRODUCTS_DATA = [
|
|
# iPhones
|
|
{
|
|
"name": "Refurbished Apple iPhone 15 Pro Max",
|
|
"brand": "Apple",
|
|
"category": "Smartphones",
|
|
"price": 94999,
|
|
"compare_price": 159900,
|
|
"image": "https://images.unsplash.com/photo-1695048133142-1a20484d2569?w=800",
|
|
"specs": "256GB Storage • Titanium Body • A17 Pro Chip • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "IPH15PM-256-NT", "title": "256GB / Natural Titanium", "price": 94999, "compare_price": 159900, "stock": 15},
|
|
{"sku": "IPH15PM-512-BT", "title": "512GB / Black Titanium", "price": 112999, "compare_price": 179900, "stock": 10},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Apple iPhone 15 Pro",
|
|
"brand": "Apple",
|
|
"category": "Smartphones",
|
|
"price": 84999,
|
|
"compare_price": 134900,
|
|
"image": "https://images.unsplash.com/photo-1695048133142-1a20484d2569?w=800",
|
|
"specs": "128GB Storage • Action Button • A17 Pro Chip • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "IPH15P-128-WT", "title": "128GB / White Titanium", "price": 84999, "compare_price": 134900, "stock": 18},
|
|
{"sku": "IPH15P-256-BT", "title": "256GB / Black Titanium", "price": 93999, "compare_price": 144900, "stock": 12},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Apple iPhone 15",
|
|
"brand": "Apple",
|
|
"category": "Smartphones",
|
|
"price": 56999,
|
|
"compare_price": 79900,
|
|
"image": "https://images.unsplash.com/photo-1592750475338-74b7b21085ab?w=800",
|
|
"specs": "128GB Storage • Dynamic Island • 48MP Camera • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "IPH15-128-BLK", "title": "128GB / Black", "price": 56999, "compare_price": 79900, "stock": 25},
|
|
{"sku": "IPH15-256-BLU", "title": "256GB / Blue", "price": 64999, "compare_price": 89900, "stock": 15},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Apple iPhone 14 Pro Max",
|
|
"brand": "Apple",
|
|
"category": "Smartphones",
|
|
"price": 74999,
|
|
"compare_price": 139900,
|
|
"image": "https://images.unsplash.com/photo-1663499482523-1c0c1bae4ce1?w=800",
|
|
"specs": "128GB Storage • Dynamic Island • A16 Bionic • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "IPH14PM-128-PUR", "title": "128GB / Deep Purple", "price": 74999, "compare_price": 139900, "stock": 20},
|
|
{"sku": "IPH14PM-256-BLK", "title": "256GB / Space Black", "price": 82999, "compare_price": 149900, "stock": 14},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Apple iPhone 14 Pro",
|
|
"brand": "Apple",
|
|
"category": "Smartphones",
|
|
"price": 66999,
|
|
"compare_price": 129900,
|
|
"image": "https://images.unsplash.com/photo-1663499482523-1c0c1bae4ce1?w=800",
|
|
"specs": "128GB Storage • 120Hz ProMotion • Dynamic Island • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "IPH14P-128-PUR", "title": "128GB / Deep Purple", "price": 66999, "compare_price": 129900, "stock": 22},
|
|
{"sku": "IPH14P-256-GLD", "title": "256GB / Gold", "price": 73999, "compare_price": 139900, "stock": 10},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Apple iPhone 14",
|
|
"brand": "Apple",
|
|
"category": "Smartphones",
|
|
"price": 44999,
|
|
"compare_price": 69900,
|
|
"image": "https://images.unsplash.com/photo-1663499482523-1c0c1bae4ce1?w=800",
|
|
"specs": "128GB Storage • Photonic Engine • Crash Detection • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "IPH14-128-MID", "title": "128GB / Midnight", "price": 44999, "compare_price": 69900, "stock": 30},
|
|
{"sku": "IPH14-256-BLU", "title": "256GB / Blue", "price": 52999, "compare_price": 79900, "stock": 18},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Apple iPhone 13 Pro Max",
|
|
"brand": "Apple",
|
|
"category": "Smartphones",
|
|
"price": 59999,
|
|
"compare_price": 129900,
|
|
"image": "https://images.unsplash.com/photo-1632661674596-df8be070a5c5?w=800",
|
|
"specs": "128GB Storage • ProMotion 120Hz • A15 Bionic • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "IPH13PM-128-SBLU", "title": "128GB / Sierra Blue", "price": 59999, "compare_price": 129900, "stock": 16},
|
|
{"sku": "IPH13PM-256-GRP", "title": "256GB / Graphite", "price": 66999, "compare_price": 139900, "stock": 11},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Apple iPhone 13",
|
|
"brand": "Apple",
|
|
"category": "Smartphones",
|
|
"price": 38999,
|
|
"compare_price": 59900,
|
|
"image": "https://images.unsplash.com/photo-1632661674596-df8be070a5c5?w=800",
|
|
"specs": "128GB Storage • Cinematic Mode • All-Day Battery • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "IPH13-128-MID", "title": "128GB / Midnight", "price": 38999, "compare_price": 59900, "stock": 40},
|
|
{"sku": "IPH13-256-STR", "title": "256GB / Starlight", "price": 45999, "compare_price": 69900, "stock": 25},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Apple iPhone 12 Pro Max",
|
|
"brand": "Apple",
|
|
"category": "Smartphones",
|
|
"price": 46999,
|
|
"compare_price": 119900,
|
|
"image": "https://images.unsplash.com/photo-1605236453806-6ff36851218e?w=800",
|
|
"specs": "128GB Storage • Ceramic Shield • LiDAR Scanner • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "IPH12PM-128-PBLU", "title": "128GB / Pacific Blue", "price": 46999, "compare_price": 119900, "stock": 14},
|
|
{"sku": "IPH12PM-256-GRP", "title": "256GB / Graphite", "price": 52999, "compare_price": 129900, "stock": 9},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Apple iPhone 12",
|
|
"brand": "Apple",
|
|
"category": "Smartphones",
|
|
"price": 28999,
|
|
"compare_price": 49900,
|
|
"image": "https://images.unsplash.com/photo-1605236453806-6ff36851218e?w=800",
|
|
"specs": "64GB Storage • Super Retina XDR • MagSafe • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "IPH12-64-BLK", "title": "64GB / Black", "price": 28999, "compare_price": 49900, "stock": 35},
|
|
{"sku": "IPH12-128-BLU", "title": "128GB / Blue", "price": 33999, "compare_price": 54900, "stock": 20},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Apple iPhone 11",
|
|
"brand": "Apple",
|
|
"category": "Smartphones",
|
|
"price": 19999,
|
|
"compare_price": 43900,
|
|
"image": "https://images.unsplash.com/photo-1574944985070-8f3ebc6b79d2?w=800",
|
|
"specs": "64GB Storage • Dual 12MP Ultra Wide • Night Mode • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "IPH11-64-BLK", "title": "64GB / Black", "price": 19999, "compare_price": 43900, "stock": 50},
|
|
{"sku": "IPH11-128-WHT", "title": "128GB / White", "price": 23999, "compare_price": 48900, "stock": 30},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Apple iPhone SE (2022)",
|
|
"brand": "Apple",
|
|
"category": "Smartphones",
|
|
"price": 18499,
|
|
"compare_price": 43900,
|
|
"image": "https://images.unsplash.com/photo-1574944985070-8f3ebc6b79d2?w=800",
|
|
"specs": "64GB Storage • A15 Bionic • 5G Speed • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "IPHSE3-64-MID", "title": "64GB / Midnight", "price": 18499, "compare_price": 43900, "stock": 22},
|
|
{"sku": "IPHSE3-128-STR", "title": "128GB / Starlight", "price": 21999, "compare_price": 48900, "stock": 15},
|
|
]
|
|
},
|
|
|
|
# Samsung Phones
|
|
{
|
|
"name": "Refurbished Samsung Galaxy S24 Ultra 5G",
|
|
"brand": "Samsung",
|
|
"category": "Smartphones",
|
|
"price": 89999,
|
|
"compare_price": 129999,
|
|
"image": "https://images.unsplash.com/photo-1610945265064-0e34e5519bbf?w=800",
|
|
"specs": "256GB / 12GB RAM • Galaxy AI • 200MP Quad Camera • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "SGS24U-256-TBLK", "title": "256GB / Titanium Black", "price": 89999, "compare_price": 129999, "stock": 12},
|
|
{"sku": "SGS24U-512-TGRAY", "title": "512GB / Titanium Gray", "price": 99999, "compare_price": 139999, "stock": 8},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Samsung Galaxy S23 Ultra 5G",
|
|
"brand": "Samsung",
|
|
"category": "Smartphones",
|
|
"price": 64999,
|
|
"compare_price": 124999,
|
|
"image": "https://images.unsplash.com/photo-1610945265064-0e34e5519bbf?w=800",
|
|
"specs": "256GB / 12GB RAM • S Pen Included • Snapdragon 8 Gen 2 • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "SGS23U-256-BLK", "title": "256GB / Phantom Black", "price": 64999, "compare_price": 124999, "stock": 18},
|
|
{"sku": "SGS23U-512-GRN", "title": "512GB / Green", "price": 72999, "compare_price": 134999, "stock": 10},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Samsung Galaxy S23 5G",
|
|
"brand": "Samsung",
|
|
"category": "Smartphones",
|
|
"price": 38999,
|
|
"compare_price": 74999,
|
|
"image": "https://images.unsplash.com/photo-1610945265064-0e34e5519bbf?w=800",
|
|
"specs": "128GB / 8GB RAM • Dynamic AMOLED 2X • Nightography • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "SGS23-128-BLK", "title": "128GB / Phantom Black", "price": 38999, "compare_price": 74999, "stock": 25},
|
|
{"sku": "SGS23-256-GRN", "title": "256GB / Green", "price": 43999, "compare_price": 79999, "stock": 15},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Samsung Galaxy S22 Ultra 5G",
|
|
"brand": "Samsung",
|
|
"category": "Smartphones",
|
|
"price": 44999,
|
|
"compare_price": 109999,
|
|
"image": "https://images.unsplash.com/photo-1610945265064-0e34e5519bbf?w=800",
|
|
"specs": "128GB / 12GB RAM • Built-in S Pen • 108MP Pro Camera • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "SGS22U-128-BUR", "title": "128GB / Burgundy", "price": 44999, "compare_price": 109999, "stock": 14},
|
|
{"sku": "SGS22U-256-BLK", "title": "256GB / Phantom Black", "price": 49999, "compare_price": 119999, "stock": 9},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Samsung Galaxy Z Fold 5 5G",
|
|
"brand": "Samsung",
|
|
"category": "Smartphones",
|
|
"price": 82999,
|
|
"compare_price": 154999,
|
|
"image": "https://images.unsplash.com/photo-1580910051074-3eb694886505?w=800",
|
|
"specs": "256GB / 12GB RAM • 7.6\" Foldable Display • Flex Hinge • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "SGZF5-256-BLK", "title": "256GB / Phantom Black", "price": 82999, "compare_price": 154999, "stock": 8},
|
|
{"sku": "SGZF5-512-BLU", "title": "512GB / Icy Blue", "price": 92999, "compare_price": 164999, "stock": 5},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Samsung Galaxy Z Flip 5 5G",
|
|
"brand": "Samsung",
|
|
"category": "Smartphones",
|
|
"price": 49999,
|
|
"compare_price": 99999,
|
|
"image": "https://images.unsplash.com/photo-1580910051074-3eb694886505?w=800",
|
|
"specs": "256GB / 8GB RAM • 3.4\" Flex Window • Compact Pocketable • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "SGZFP5-256-MNT", "title": "256GB / Mint", "price": 49999, "compare_price": 99999, "stock": 15},
|
|
{"sku": "SGZFP5-512-GRA", "title": "512GB / Graphite", "price": 57999, "compare_price": 109999, "stock": 8},
|
|
]
|
|
},
|
|
|
|
# OnePlus Phones
|
|
{
|
|
"name": "Refurbished OnePlus 12 5G",
|
|
"brand": "OnePlus",
|
|
"category": "Smartphones",
|
|
"price": 52999,
|
|
"compare_price": 64999,
|
|
"image": "https://images.unsplash.com/photo-1598327105666-5b89351aff97?w=800",
|
|
"specs": "256GB / 12GB RAM • Snapdragon 8 Gen 3 • 4th Gen Hasselblad • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "OP12-256-GRN", "title": "256GB / Flowy Emerald", "price": 52999, "compare_price": 64999, "stock": 16},
|
|
{"sku": "OP12-512-BLK", "title": "512GB / Silky Black", "price": 59999, "compare_price": 69999, "stock": 10},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished OnePlus 11 5G",
|
|
"brand": "OnePlus",
|
|
"category": "Smartphones",
|
|
"price": 36999,
|
|
"compare_price": 56999,
|
|
"image": "https://images.unsplash.com/photo-1598327105666-5b89351aff97?w=800",
|
|
"specs": "128GB / 8GB RAM • 100W SUPERVOOC • Hasselblad Camera • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "OP11-128-BLK", "title": "128GB / Titan Black", "price": 36999, "compare_price": 56999, "stock": 20},
|
|
{"sku": "OP11-256-GRN", "title": "256GB / Eternal Green", "price": 41999, "compare_price": 61999, "stock": 14},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished OnePlus 11R 5G",
|
|
"brand": "OnePlus",
|
|
"category": "Smartphones",
|
|
"price": 26999,
|
|
"compare_price": 39999,
|
|
"image": "https://images.unsplash.com/photo-1598327105666-5b89351aff97?w=800",
|
|
"specs": "128GB / 8GB RAM • Snapdragon 8+ Gen 1 • 120Hz Fluid AMOLED • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "OP11R-128-BLK", "title": "128GB / Sonic Black", "price": 26999, "compare_price": 39999, "stock": 30},
|
|
{"sku": "OP11R-256-SLV", "title": "256GB / Galactic Silver", "price": 30999, "compare_price": 44999, "stock": 18},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished OnePlus Nord 3 5G",
|
|
"brand": "OnePlus",
|
|
"category": "Smartphones",
|
|
"price": 18999,
|
|
"compare_price": 33999,
|
|
"image": "https://images.unsplash.com/photo-1598327105666-5b89351aff97?w=800",
|
|
"specs": "128GB / 8GB RAM • MediaTek Dimensity 9000 • 50MP Sony IMX890 • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "OPN3-128-GRN", "title": "128GB / Misty Green", "price": 18999, "compare_price": 33999, "stock": 25},
|
|
{"sku": "OPN3-256-GRY", "title": "256GB / Tempest Gray", "price": 21999, "compare_price": 37999, "stock": 15},
|
|
]
|
|
},
|
|
|
|
# Google Pixels
|
|
{
|
|
"name": "Refurbished Google Pixel 8 Pro",
|
|
"brand": "Google",
|
|
"category": "Smartphones",
|
|
"price": 58999,
|
|
"compare_price": 106999,
|
|
"image": "https://images.unsplash.com/photo-1598327105666-5b89351aff97?w=800",
|
|
"specs": "128GB / 12GB RAM • Google Tensor G3 • Temperature Sensor • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "GPX8P-128-OBS", "title": "128GB / Obsidian", "price": 58999, "compare_price": 106999, "stock": 14},
|
|
{"sku": "GPX8P-256-BAY", "title": "256GB / Bay Blue", "price": 65999, "compare_price": 113999, "stock": 9},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Google Pixel 8",
|
|
"brand": "Google",
|
|
"category": "Smartphones",
|
|
"price": 41999,
|
|
"compare_price": 75999,
|
|
"image": "https://images.unsplash.com/photo-1598327105666-5b89351aff97?w=800",
|
|
"specs": "128GB / 8GB RAM • Actua Display • Best Take AI • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "GPX8-128-HZL", "title": "128GB / Hazel", "price": 41999, "compare_price": 75999, "stock": 20},
|
|
{"sku": "GPX8-256-OBS", "title": "256GB / Obsidian", "price": 47999, "compare_price": 82999, "stock": 12},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Google Pixel 7a",
|
|
"brand": "Google",
|
|
"category": "Smartphones",
|
|
"price": 23999,
|
|
"compare_price": 43999,
|
|
"image": "https://images.unsplash.com/photo-1598327105666-5b89351aff97?w=800",
|
|
"specs": "128GB / 8GB RAM • Google Tensor G2 • Wireless Charging • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "GPX7A-128-CHA", "title": "128GB / Charcoal", "price": 23999, "compare_price": 43999, "stock": 28},
|
|
{"sku": "GPX7A-128-SEA", "title": "128GB / Sea", "price": 23999, "compare_price": 43999, "stock": 15},
|
|
]
|
|
},
|
|
|
|
# Xiaomi / Poco
|
|
{
|
|
"name": "Refurbished Xiaomi 13 Pro 5G",
|
|
"brand": "Xiaomi",
|
|
"category": "Smartphones",
|
|
"price": 44999,
|
|
"compare_price": 79999,
|
|
"image": "https://images.unsplash.com/photo-1511707171634-5f897ff02aa9?w=800",
|
|
"specs": "256GB / 12GB RAM • Leica 1-inch Camera • Snapdragon 8 Gen 2 • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "MI13P-256-CBLK", "title": "256GB / Ceramic Black", "price": 44999, "compare_price": 79999, "stock": 10},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Redmi Note 13 Pro+ 5G",
|
|
"brand": "Xiaomi",
|
|
"category": "Smartphones",
|
|
"price": 21999,
|
|
"compare_price": 31999,
|
|
"image": "https://images.unsplash.com/photo-1511707171634-5f897ff02aa9?w=800",
|
|
"specs": "256GB / 8GB RAM • 200MP OIS Camera • 120W HyperCharge • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "RN13PP-256-PUR", "title": "256GB / Fusion Purple", "price": 21999, "compare_price": 31999, "stock": 35},
|
|
{"sku": "RN13PP-512-BLK", "title": "512GB / Fusion Black", "price": 25999, "compare_price": 35999, "stock": 20},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished POCO F5 5G",
|
|
"brand": "Xiaomi",
|
|
"category": "Smartphones",
|
|
"price": 18999,
|
|
"compare_price": 29999,
|
|
"image": "https://images.unsplash.com/photo-1511707171634-5f897ff02aa9?w=800",
|
|
"specs": "256GB / 8GB RAM • Snapdragon 7+ Gen 2 • 120Hz AMOLED • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "POCOF5-256-BLK", "title": "256GB / Carbon Black", "price": 18999, "compare_price": 29999, "stock": 22},
|
|
]
|
|
},
|
|
|
|
# Tablets & Laptops
|
|
{
|
|
"name": "Refurbished Apple iPad Pro 12.9\" M2 (6th Gen)",
|
|
"brand": "Apple",
|
|
"category": "Tablets",
|
|
"price": 78999,
|
|
"compare_price": 112900,
|
|
"image": "https://images.unsplash.com/photo-1544244015-0df4b3ffc6b0?w=800",
|
|
"specs": "128GB Wi-Fi • M2 Chip • Liquid Retina XDR • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "IPADP6-128-GRY", "title": "128GB / Space Gray", "price": 78999, "compare_price": 112900, "stock": 10},
|
|
{"sku": "IPADP6-256-SLV", "title": "256GB / Silver", "price": 86999, "compare_price": 122900, "stock": 6},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Apple iPad Air M1 (5th Gen)",
|
|
"brand": "Apple",
|
|
"category": "Tablets",
|
|
"price": 41999,
|
|
"compare_price": 59900,
|
|
"image": "https://images.unsplash.com/photo-1544244015-0df4b3ffc6b0?w=800",
|
|
"specs": "64GB Wi-Fi • Apple M1 Chip • 10.9\" Liquid Retina • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "IPADA5-64-GRY", "title": "64GB / Space Gray", "price": 41999, "compare_price": 59900, "stock": 18},
|
|
{"sku": "IPADA5-256-BLU", "title": "256GB / Blue", "price": 53999, "compare_price": 74900, "stock": 10},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Apple iPad 10th Gen 10.9\"",
|
|
"brand": "Apple",
|
|
"category": "Tablets",
|
|
"price": 27999,
|
|
"compare_price": 44900,
|
|
"image": "https://images.unsplash.com/photo-1544244015-0df4b3ffc6b0?w=800",
|
|
"specs": "64GB Wi-Fi • A14 Bionic • All-Screen Design • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "IPAD10-64-BLU", "title": "64GB / Blue", "price": 27999, "compare_price": 44900, "stock": 25},
|
|
{"sku": "IPAD10-256-SLV", "title": "256GB / Silver", "price": 38999, "compare_price": 59900, "stock": 14},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Apple MacBook Air M2 13.6\"",
|
|
"brand": "Apple",
|
|
"category": "Laptops",
|
|
"price": 74999,
|
|
"compare_price": 119900,
|
|
"image": "https://images.unsplash.com/photo-1517336714731-489689fd1ca8?w=800",
|
|
"specs": "8GB RAM / 256GB SSD • M2 8-core CPU • Liquid Retina • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "MBA-M2-256-MID", "title": "8GB/256GB / Midnight", "price": 74999, "compare_price": 119900, "stock": 12},
|
|
{"sku": "MBA-M2-512-STR", "title": "16GB/512GB / Starlight", "price": 94999, "compare_price": 139900, "stock": 8},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Apple MacBook Air M1 13.3\"",
|
|
"brand": "Apple",
|
|
"category": "Laptops",
|
|
"price": 51999,
|
|
"compare_price": 99900,
|
|
"image": "https://images.unsplash.com/photo-1517336714731-489689fd1ca8?w=800",
|
|
"specs": "8GB RAM / 256GB SSD • M1 8-core CPU • Silent Fanless • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "MBA-M1-256-GRY", "title": "8GB/256GB / Space Gray", "price": 51999, "compare_price": 99900, "stock": 20},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Apple MacBook Pro M2 Pro 14\"",
|
|
"brand": "Apple",
|
|
"category": "Laptops",
|
|
"price": 118999,
|
|
"compare_price": 199900,
|
|
"image": "https://images.unsplash.com/photo-1517336714731-489689fd1ca8?w=800",
|
|
"specs": "16GB RAM / 512GB SSD • M2 Pro 10-core CPU • Liquid Retina XDR • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "MBP14-M2P-512", "title": "16GB/512GB / Space Gray", "price": 118999, "compare_price": 199900, "stock": 5},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Dell XPS 13 Core i7 11th Gen",
|
|
"brand": "Dell",
|
|
"category": "Laptops",
|
|
"price": 48999,
|
|
"compare_price": 124900,
|
|
"image": "https://images.unsplash.com/photo-1593642632823-8f785ba67e45?w=800",
|
|
"specs": "16GB RAM / 512GB NVMe SSD • Core i7-1165G7 • FHD+ Touch • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "DELLXPS13-512", "title": "16GB/512GB / Platinum Silver", "price": 48999, "compare_price": 124900, "stock": 14},
|
|
]
|
|
},
|
|
|
|
# Consoles & Audio
|
|
{
|
|
"name": "Refurbished Sony PlayStation 5 Disc Edition",
|
|
"brand": "Sony",
|
|
"category": "Gaming Consoles",
|
|
"price": 39999,
|
|
"compare_price": 54990,
|
|
"image": "https://images.unsplash.com/photo-1606813907291-d86efa9b94db?w=800",
|
|
"specs": "825GB Ultra-High Speed SSD • DualSense Controller • 4K 120Hz Gaming • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "PS5-DISC-825", "title": "825GB SSD / White", "price": 39999, "compare_price": 54990, "stock": 15},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Sony WH-1000XM5 Noise Canceling Headphones",
|
|
"brand": "Sony",
|
|
"category": "Audio & Headphones",
|
|
"price": 19999,
|
|
"compare_price": 34990,
|
|
"image": "https://images.unsplash.com/photo-1505740420928-5e560c06d30e?w=800",
|
|
"specs": "Auto NC Optimizer • 30-Hour Battery Life • Crystal Clear Hands-Free • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "SONYXM5-BLK", "title": "Black / ANC Over-Ear", "price": 19999, "compare_price": 34990, "stock": 25},
|
|
{"sku": "SONYXM5-SLV", "title": "Silver / ANC Over-Ear", "price": 19999, "compare_price": 34990, "stock": 15},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Bose QuietComfort 45 Headphones",
|
|
"brand": "Bose",
|
|
"category": "Audio & Headphones",
|
|
"price": 17999,
|
|
"compare_price": 29900,
|
|
"image": "https://images.unsplash.com/photo-1505740420928-5e560c06d30e?w=800",
|
|
"specs": "Quiet & Aware Modes • High-Fidelity Audio • 24-Hour Battery • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "BOSEQC45-BLK", "title": "Triple Black", "price": 17999, "compare_price": 29900, "stock": 18},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Apple AirPods Pro (2nd Generation)",
|
|
"brand": "Apple",
|
|
"category": "Audio & Headphones",
|
|
"price": 14999,
|
|
"compare_price": 26900,
|
|
"image": "https://images.unsplash.com/photo-1600294037681-c80b4cb5b434?w=800",
|
|
"specs": "H2 Chip • 2x Active Noise Cancellation • Adaptive Audio • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "AIRPODSPRO2", "title": "MagSafe Case (USB-C)", "price": 14999, "compare_price": 26900, "stock": 40},
|
|
]
|
|
},
|
|
{
|
|
"name": "Refurbished Apple Watch Series 9 GPS 45mm",
|
|
"brand": "Apple",
|
|
"category": "Smartwatches",
|
|
"price": 29999,
|
|
"compare_price": 44900,
|
|
"image": "https://images.unsplash.com/photo-1508685096489-7aacd43bd3b1?w=800",
|
|
"specs": "45mm Aluminum Case • Double Tap Gesture • S9 SiP • Refurbished Superb",
|
|
"variants": [
|
|
{"sku": "APW9-45-MID", "title": "45mm / Midnight", "price": 29999, "compare_price": 44900, "stock": 20},
|
|
{"sku": "APW9-45-STR", "title": "45mm / Starlight", "price": 29999, "compare_price": 44900, "stock": 12},
|
|
]
|
|
}
|
|
]
|
|
|
|
print(f"Processing {len(PRODUCTS_DATA)} Cashify refurbished products...")
|
|
|
|
inserted_count = 0
|
|
for item in PRODUCTS_DATA:
|
|
slug = re.sub(r'[^a-z0-9]+', '-', item["name"].lower()).strip('-')
|
|
|
|
# Check if exists
|
|
existing = db.query(Product).filter(Product.slug == slug).first()
|
|
if existing:
|
|
prod = existing
|
|
else:
|
|
prod_id = str(ulid.ULID())
|
|
brand_id = brand_map.get(item["brand"])
|
|
cat_id = cat_map.get(item["category"])
|
|
|
|
prod = Product(
|
|
product_id=prod_id,
|
|
name=item["name"],
|
|
slug=slug,
|
|
full_path=f"/products/{slug}",
|
|
brand_id=brand_id,
|
|
category_id=cat_id,
|
|
description=f"### {item['name']}\n\n**Key Specs**: {item['specs']}\n\nAll iFixKart refurbished gadgets undergo a 32-point quality check, include a 6-month warranty, free shipping, and guaranteed battery health >= 85%.",
|
|
status="active"
|
|
)
|
|
db.add(prod)
|
|
db.commit()
|
|
db.refresh(prod)
|
|
inserted_count += 1
|
|
|
|
# Primary Image
|
|
p_img = ProductImage(
|
|
image_id=str(ulid.ULID()),
|
|
product_id=prod.product_id,
|
|
image_url=item["image"],
|
|
alt_text=item["name"],
|
|
sort_order=1
|
|
)
|
|
db.add(p_img)
|
|
db.commit()
|
|
|
|
# Variants
|
|
for var_data in item["variants"]:
|
|
var_existing = db.query(ProductVariant).filter(ProductVariant.sku == var_data["sku"]).first()
|
|
if not var_existing:
|
|
pv = ProductVariant(
|
|
variant_id=str(ulid.ULID()),
|
|
product_id=prod.product_id,
|
|
sku=var_data["sku"],
|
|
price=Decimal(str(var_data["price"])),
|
|
compare_price=Decimal(str(var_data["compare_price"])),
|
|
cost_price=Decimal(str(int(var_data["price"] * 0.7))),
|
|
status="active"
|
|
)
|
|
db.add(pv)
|
|
db.commit()
|
|
|
|
print(f"Successfully populated {inserted_count} new Cashify products into DB! Total catalog size: {db.query(Product).count()}")
|
|
db.close()
|