|
|
|
|
|
import os |
|
|
import sys |
|
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) |
|
|
|
|
|
from app import create_app, db |
|
|
from app.models import ( |
|
|
User, |
|
|
Metal, |
|
|
UserMetal, |
|
|
Transaction, |
|
|
ReferralCommission, |
|
|
Notification, |
|
|
) |
|
|
|
|
|
|
|
|
def init_database(): |
|
|
app = create_app() |
|
|
with app.app_context(): |
|
|
db.create_all() |
|
|
print("Base de données initialisée avec succès!") |
|
|
|
|
|
|
|
|
def create_admin_user(): |
|
|
app = create_app() |
|
|
with app.app_context(): |
|
|
from werkzeug.security import generate_password_hash |
|
|
|
|
|
admin = User( |
|
|
phone="+22812345678", |
|
|
country_code="+228", |
|
|
password=generate_password_hash("admin123"), |
|
|
) |
|
|
admin.is_admin = True |
|
|
db.session.add(admin) |
|
|
db.session.commit() |
|
|
|
|
|
print( |
|
|
f"Utilisateur admin créé avec le code de parrainage: {admin.referral_code}" |
|
|
) |
|
|
print("Téléphone: +22812345678") |
|
|
print("Mot de passe: admin123") |
|
|
|
|
|
|
|
|
def create_sample_metals(): |
|
|
app = create_app() |
|
|
with app.app_context(): |
|
|
metals_data = [ |
|
|
{ |
|
|
"name": "Lingot d'Or Premium", |
|
|
"description": "Lingot d'or pur 24 carats, investissement sécurisé", |
|
|
"price": 5000, |
|
|
"daily_gain": 450, |
|
|
"cycle_days": 60, |
|
|
"image_url": "/static/images/gold-bar.jpg", |
|
|
}, |
|
|
{ |
|
|
"name": "Diamant Brut", |
|
|
"description": "Diamant naturel de haute qualité", |
|
|
"price": 10000, |
|
|
"daily_gain": 850, |
|
|
"cycle_days": 90, |
|
|
"image_url": "/static/images/diamond.jpg", |
|
|
}, |
|
|
{ |
|
|
"name": "Argent Sterling", |
|
|
"description": "Lingot d'argent sterling 925", |
|
|
"price": 2500, |
|
|
"daily_gain": 200, |
|
|
"cycle_days": 45, |
|
|
"image_url": "/static/images/silver-bar.jpg", |
|
|
}, |
|
|
{ |
|
|
"name": "Platine Pur", |
|
|
"description": "Lingot de platine pur, investissement rare", |
|
|
"price": 15000, |
|
|
"daily_gain": 1200, |
|
|
"cycle_days": 120, |
|
|
"image_url": "/static/images/platinum-bar.jpg", |
|
|
}, |
|
|
] |
|
|
|
|
|
for metal_data in metals_data: |
|
|
metal = Metal(**metal_data) |
|
|
db.session.add(metal) |
|
|
|
|
|
db.session.commit() |
|
|
print("Métaux exemples créés avec succès!") |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
if len(sys.argv) > 1: |
|
|
command = sys.argv[1] |
|
|
|
|
|
if command == "init-db": |
|
|
init_database() |
|
|
elif command == "create-admin": |
|
|
create_admin_user() |
|
|
elif command == "create-metals": |
|
|
create_sample_metals() |
|
|
else: |
|
|
print("Commandes disponibles:") |
|
|
print(" python setup.py init-db") |
|
|
print(" python setup.py create-admin") |
|
|
print(" python setup.py create-metals") |
|
|
else: |
|
|
print("Usage: python setup.py <command>") |
|
|
print("Commandes: init-db, create-admin, create-metals") |
|
|
|