File size: 3,177 Bytes
08ec4c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env python3
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")