victoirefinal7vi commited on
Commit
f30870e
·
verified ·
1 Parent(s): 49979e8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -0
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # app.py
3
+ from flask import Flask, render_template, request, jsonify
4
+ import asyncio
5
+ from concurrent.futures import ThreadPoolExecutor
6
+ import json
7
+ import os
8
+ from datetime import datetime
9
+ # Importez toutes vos classes existantes ici
10
+ from cc import AsyncAccountCreator, save_accounts
11
+
12
+ app = Flask(__name__)
13
+ executor = ThreadPoolExecutor(max_workers=1)
14
+
15
+ def async_creation(num_accounts):
16
+ async def run_creation():
17
+ creator = AsyncAccountCreator(
18
+ 'https://gabaohub.alwaysdata.net',
19
+ max_concurrent=10,
20
+ rate_limit=20
21
+ )
22
+
23
+ results = await creator.create_multiple_accounts(num_accounts)
24
+
25
+ if results['accounts']:
26
+ filename = f"accounts_{datetime.now().strftime('%Y%m%d_%H%M%S')}.json"
27
+ await save_accounts(results['accounts'], filename)
28
+ results['filename'] = filename
29
+
30
+ return results
31
+
32
+ return asyncio.run(run_creation())
33
+
34
+ @app.route('/')
35
+ def index():
36
+ return render_template('index.html')
37
+
38
+ @app.route('/create_accounts', methods=['POST'])
39
+ def create_accounts():
40
+ try:
41
+ num_accounts = int(request.form['num_accounts'])
42
+ if num_accounts <= 0:
43
+ return jsonify({'error': 'Le nombre de comptes doit être positif'}), 400
44
+
45
+ # Lancer la création de comptes en arrière-plan
46
+ future = executor.submit(async_creation, num_accounts)
47
+
48
+ return jsonify({
49
+ 'message': f'Création de {num_accounts} comptes lancée avec succès',
50
+ 'status': 'pending'
51
+ })
52
+
53
+ except ValueError:
54
+ return jsonify({'error': 'Nombre de comptes invalide'}), 400
55
+ except Exception as e:
56
+ return jsonify({'error': str(e)}), 500
57
+
58
+ @app.route('/check_status')
59
+ def check_status():
60
+ # Cette route pourrait être implémentée pour vérifier l'état d'avancement
61
+ # Pour l'instant, retourne un statut générique
62
+ return jsonify({
63
+ 'status': 'running',
64
+ 'accounts_created': 0,
65
+ 'total_accounts': 0
66
+ })
67
+