| from flask import Flask, render_template, request, jsonify, redirect, url_for |
| import requests |
| from bs4 import BeautifulSoup |
| import random |
| import string |
| import json |
| import threading |
| import os |
| import time |
| from datetime import datetime |
|
|
| app = Flask(__name__) |
|
|
| |
| config = { |
| 'base_url': "https://ivoire-startup-tracker-edithbrou.replit.app", |
| 'accounts_file': "accounts_data.json", |
| 'is_running': False, |
| 'progress': { |
| 'total': 0, |
| 'current': 0, |
| 'success': 0, |
| 'failed': 0, |
| 'last_username': '', |
| 'last_status': '', |
| 'start_time': None, |
| 'end_time': None |
| } |
| } |
|
|
| |
| def generate_random_username(min_length=8, max_length=12): |
| """Génère un nom d'utilisateur aléatoire d'une longueur raisonnable""" |
| length = random.randint(min_length, max_length) |
| return ''.join(random.choice(string.ascii_lowercase) for _ in range(length)) |
|
|
| |
| def generate_random_email(): |
| """Génère une adresse email aléatoire""" |
| username = ''.join(random.choice(string.ascii_lowercase) for _ in range(12)) |
| domains = ["gmail.com", "yahoo.com", "outlook.com", "example.com"] |
| return f"{username}@{random.choice(domains)}" |
|
|
| |
| def generate_random_password(length=10): |
| """Génère un mot de passe aléatoire avec un mélange de caractères""" |
| chars = string.ascii_letters + string.digits + string.punctuation |
| return ''.join(random.choice(chars) for _ in range(length)) |
|
|
| |
| def create_account(is_startup_rep=False): |
| """Crée un compte sur le site web""" |
| register_url = f"{config['base_url']}/register" |
| |
| |
| session = requests.Session() |
| try: |
| response = session.get(register_url) |
| |
| if response.status_code != 200: |
| return {'success': False, 'error': f"Erreur lors de l'accès à la page: {response.status_code}"} |
| |
| |
| soup = BeautifulSoup(response.text, 'html.parser') |
| csrf_token = soup.find('input', {'id': 'csrf_token'}).get('value') |
| |
| if not csrf_token: |
| return {'success': False, 'error': "Impossible de trouver le token CSRF"} |
| |
| |
| username = generate_random_username() |
| email = generate_random_email() |
| password = generate_random_password() |
| |
| |
| form_data = { |
| 'csrf_token': csrf_token, |
| 'username': username, |
| 'email': email, |
| 'password': password, |
| 'confirm_password': password, |
| 'submit': 'Register' |
| } |
| |
| |
| if is_startup_rep: |
| form_data['is_startup_rep'] = 'y' |
| |
| |
| headers = { |
| 'Referer': register_url, |
| 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36' |
| } |
| |
| response = session.post(register_url, data=form_data, headers=headers) |
| |
| result = { |
| 'success': response.status_code == 200 or response.status_code == 302, |
| 'username': username, |
| 'email': email, |
| 'password': password, |
| 'is_startup_rep': is_startup_rep, |
| 'created_at': datetime.now().strftime("%Y-%m-%d %H:%M:%S"), |
| 'status_code': response.status_code |
| } |
| |
| return result |
| |
| except Exception as e: |
| return {'success': False, 'error': str(e)} |
|
|
| |
| def create_accounts_background(num_accounts, startup_ratio=0.3): |
| config['progress'] = { |
| 'total': num_accounts, |
| 'current': 0, |
| 'success': 0, |
| 'failed': 0, |
| 'last_username': '', |
| 'last_status': 'Démarrage...', |
| 'start_time': datetime.now().strftime("%Y-%m-%d %H:%M:%S"), |
| 'end_time': None |
| } |
| |
| |
| accounts = [] |
| if os.path.exists(config['accounts_file']): |
| try: |
| with open(config['accounts_file'], 'r') as f: |
| accounts = json.load(f) |
| except: |
| accounts = [] |
| |
| for i in range(num_accounts): |
| if not config['is_running']: |
| break |
| |
| is_startup = random.random() < startup_ratio |
| |
| config['progress']['current'] = i + 1 |
| config['progress']['last_status'] = f"Création du compte {i+1}/{num_accounts}..." |
| |
| result = create_account(is_startup_rep=is_startup) |
| |
| if result.get('success', False): |
| config['progress']['success'] += 1 |
| config['progress']['last_username'] = result['username'] |
| config['progress']['last_status'] = f"Compte {i+1} créé avec succès" |
| accounts.append(result) |
| else: |
| config['progress']['failed'] += 1 |
| config['progress']['last_status'] = f"Échec de la création du compte {i+1}: {result.get('error', 'Erreur inconnue')}" |
| |
| |
| with open(config['accounts_file'], 'w') as f: |
| json.dump(accounts, f, indent=2) |
| |
| |
| time.sleep(1) |
| |
| config['is_running'] = False |
| config['progress']['end_time'] = datetime.now().strftime("%Y-%m-%d %H:%M:%S") |
| config['progress']['last_status'] = "Terminé" |
| |
| |
| with open(config['accounts_file'], 'w') as f: |
| json.dump(accounts, f, indent=2) |
|
|
| |
| @app.route('/') |
| def index(): |
| return render_template('index.html', config=config) |
|
|
| @app.route('/start', methods=['POST']) |
| def start(): |
| if config['is_running']: |
| return jsonify({"status": "error", "message": "Une génération est déjà en cours"}) |
| |
| num_accounts = int(request.form.get('num_accounts', 10)) |
| startup_ratio = float(request.form.get('startup_ratio', 0.3)) |
| |
| config['is_running'] = True |
| |
| |
| thread = threading.Thread(target=create_accounts_background, args=(num_accounts, startup_ratio)) |
| thread.daemon = True |
| thread.start() |
| |
| return jsonify({"status": "success", "message": "Génération démarrée"}) |
|
|
| @app.route('/stop', methods=['POST']) |
| def stop(): |
| config['is_running'] = False |
| return jsonify({"status": "success", "message": "Arrêt demandé"}) |
|
|
| @app.route('/progress') |
| def progress(): |
| return jsonify(config['progress']) |
|
|
| @app.route('/accounts') |
| def view_accounts(): |
| page = int(request.args.get('page', 1)) |
| per_page = 20 |
| |
| accounts = [] |
| if os.path.exists(config['accounts_file']): |
| try: |
| with open(config['accounts_file'], 'r') as f: |
| accounts = json.load(f) |
| except: |
| accounts = [] |
| |
| total_accounts = len(accounts) |
| total_pages = (total_accounts + per_page - 1) // per_page |
| |
| start_idx = (page - 1) * per_page |
| end_idx = start_idx + per_page |
| |
| current_accounts = accounts[start_idx:end_idx] |
| |
| return render_template( |
| 'accounts.html', |
| accounts=current_accounts, |
| page=page, |
| total_pages=total_pages, |
| total_accounts=total_accounts |
| ) |
|
|
| @app.route('/script.js') |
| def serve_js(): |
| return render_template('script.js'), 200, {'Content-Type': 'application/javascript'} |
|
|
| if __name__ == '__main__': |
| app.run(debug=True) |