Spaces:
Sleeping
Sleeping
| # app.py | |
| from flask import Flask, render_template, request, jsonify | |
| import asyncio | |
| from concurrent.futures import ThreadPoolExecutor | |
| import json | |
| import os | |
| from datetime import datetime | |
| # Importez toutes vos classes existantes ici | |
| from cc import AsyncAccountCreator, save_accounts | |
| app = Flask(__name__) | |
| executor = ThreadPoolExecutor(max_workers=1) | |
| def async_creation(num_accounts): | |
| async def run_creation(): | |
| creator = AsyncAccountCreator( | |
| 'https://gabaohub.alwaysdata.net', | |
| max_concurrent=10, | |
| rate_limit=20 | |
| ) | |
| results = await creator.create_multiple_accounts(num_accounts) | |
| if results['accounts']: | |
| filename = f"accounts_{datetime.now().strftime('%Y%m%d_%H%M%S')}.json" | |
| await save_accounts(results['accounts'], filename) | |
| results['filename'] = filename | |
| return results | |
| return asyncio.run(run_creation()) | |
| def index(): | |
| return render_template('index.html') | |
| def create_accounts(): | |
| try: | |
| num_accounts = int(request.form['num_accounts']) | |
| if num_accounts <= 0: | |
| return jsonify({'error': 'Le nombre de comptes doit être positif'}), 400 | |
| # Lancer la création de comptes en arrière-plan | |
| future = executor.submit(async_creation, num_accounts) | |
| return jsonify({ | |
| 'message': f'Création de {num_accounts} comptes lancée avec succès', | |
| 'status': 'pending' | |
| }) | |
| except ValueError: | |
| return jsonify({'error': 'Nombre de comptes invalide'}), 400 | |
| except Exception as e: | |
| return jsonify({'error': str(e)}), 500 | |
| def check_status(): | |
| # Cette route pourrait être implémentée pour vérifier l'état d'avancement | |
| # Pour l'instant, retourne un statut générique | |
| return jsonify({ | |
| 'status': 'running', | |
| 'accounts_created': 0, | |
| 'total_accounts': 0 | |
| }) | |