ai-web-scraper-chat / routers /electronics_router.py
pvanand's picture
Update routers/electronics_router.py
8e2fea8 verified
raw
history blame
1.6 kB
# routers/electronics_router.py
from fastapi import APIRouter
from typing import List
from pydantic import BaseModel
import random
router = APIRouter(prefix="/api/electronics", tags=["electronics"])
@router.get("/products")
async def get_products():
# Sample data generator
categories = ["Smartphones", "Laptops", "Tablets", "Smartwatches"]
products = []
# for i in range(20):
# category = random.choice(categories)
# specs = {
# "Smartphones": {
# "screen": f"{random.choice([5.5, 6.1, 6.7])} inches",
# "storage": f"{random.choice([64, 128, 256, 512])}GB",
# "ram": f"{random.choice([4, 6, 8, 12])}GB",
# "camera": f"{random.choice([12, 48, 64, 108])}MP"
# },
# "Laptops": {
# "screen": f"{random.choice([13, 14, 15.6, 16])} inches",
# "storage": f"{random.choice([256, 512, 1024])}GB SSD",
# "ram": f"{random.choice([8, 16, 32])}GB",
# "processor": f"Core i{random.choice([5, 7, 9])}"
# }
# }.get(category, {"specs": "Basic specifications"})
# products.append({
# "id": i + 1,
# "name": f"{category} Pro {random.randint(1, 100)}",
# "category": category,
# "price": round(random.uniform(299.99, 2999.99), 2),
# "specs": specs,
# "stock": random.randint(0, 100),
# "rating": round(random.uniform(3.5, 5.0), 1)
# })
return {"products": products}