59 lines
2.3 KiB
Python
59 lines
2.3 KiB
Python
from sqlmodel import Session
|
|
from app.core.database import engine
|
|
from app.models.business import Business
|
|
from app.models.coupon import Coupon
|
|
from datetime import datetime, timedelta
|
|
import random
|
|
|
|
def seed_data():
|
|
with Session(engine) as session:
|
|
# 5 Tourist Spots (Businesses)
|
|
categories = ["Restaurante", "Area Turistica", "Bebidas", "Viajes de Turismo"]
|
|
|
|
tourist_spots = [
|
|
{"name": "Finca El Explorador", "area": "Boquete", "lat": 8.7845, "lng": -82.4350},
|
|
{"name": "Cascada San Ramón", "area": "Boquete", "lat": 8.8120, "lng": -82.4650},
|
|
{"name": "Balneario Majagua", "area": "Dolega", "lat": 8.5550, "lng": -82.4210},
|
|
{"name": "Parque Miguel de Cervantes", "area": "David", "lat": 8.4275, "lng": -82.4285},
|
|
{"name": "Cangilones de Gualaca", "area": "Dolega", "lat": 8.5230, "lng": -82.3120}
|
|
]
|
|
|
|
created_businesses = []
|
|
for spot in tourist_spots:
|
|
biz = Business(
|
|
name=spot["name"],
|
|
address=f"Cerca de {spot['name']}, sector {spot['area']}",
|
|
phone=f"6{random.randint(1000000, 9999999)}",
|
|
category=random.choice(categories),
|
|
area=spot["area"],
|
|
latitude=spot["lat"],
|
|
longitude=spot["lng"]
|
|
)
|
|
session.add(biz)
|
|
session.flush() # To get the ID
|
|
created_businesses.append(biz)
|
|
|
|
# 5 Coupons (Offers)
|
|
for i in range(5):
|
|
biz = random.choice(created_businesses)
|
|
coupon = Coupon(
|
|
title=f"Oferta Especial {i+1} - {biz.name}",
|
|
description=f"¡Aprovecha esta increíble oferta en {biz.name}! Solo por tiempo limitado.",
|
|
business_id=biz.id,
|
|
business_name=biz.name,
|
|
business_address=biz.address,
|
|
business_phone=biz.phone,
|
|
category=biz.category,
|
|
discount_percentage=random.randint(10, 50),
|
|
valid_from=datetime.now().isoformat(),
|
|
valid_until=(datetime.now() + timedelta(days=30)).isoformat(),
|
|
is_active=True
|
|
)
|
|
session.add(coupon)
|
|
|
|
session.commit()
|
|
print("Successfully seeded 5 tourist spots and 5 offers.")
|
|
|
|
if __name__ == "__main__":
|
|
seed_data()
|