You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
981 B
Python
33 lines
981 B
Python
from faker import Faker
|
|
import random
|
|
import asyncio
|
|
|
|
# Initialiser Faker
|
|
fake = Faker('fr_FR')
|
|
|
|
# Liste de catégories de produits
|
|
categories = ['vélo', 'raquettes', 'chaussures', 'ballons', 'sacs de sport', 'équipements de fitness']
|
|
|
|
# Liste de marques fictives
|
|
marques = ['SportMax', 'FitLife', 'AthléTech', 'VéloRapide', 'RaquettesPro', 'ChaussSport']
|
|
|
|
async def generer_produits(nombre):
|
|
"""
|
|
Génère un nombre spécifié de produits fictifs d'articles de sport de manière asynchrone.
|
|
|
|
Args:
|
|
nombre (int): Le nombre de produits à générer.
|
|
|
|
Yields:
|
|
dict: Un dictionnaire représentant un produit.
|
|
"""
|
|
for _ in range(nombre):
|
|
produit = {
|
|
'nom': fake.word() + ' ' + random.choice(categories),
|
|
'marque': random.choice(marques),
|
|
'prix': round(random.uniform(10, 500), 2),
|
|
'description': fake.sentence(),
|
|
'disponible': fake.boolean()
|
|
}
|
|
yield produit
|