Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
#yo
|
2 |
from flask import Flask, render_template, request, jsonify, redirect, url_for
|
3 |
import requests
|
4 |
from bs4 import BeautifulSoup
|
@@ -227,318 +226,11 @@ def view_accounts():
|
|
227 |
total_accounts=total_accounts
|
228 |
)
|
229 |
|
230 |
-
if __name__ == '__main__':
|
231 |
-
# Get the directory of the current script
|
232 |
-
current_dir = os.path.dirname(os.path.abspath(__file__))
|
233 |
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
os.makedirs(templates_dir)
|
238 |
|
239 |
-
# Create the HTML template files using absolute paths
|
240 |
-
index_html_path = os.path.join(templates_dir, 'index.html')
|
241 |
-
accounts_html_path = os.path.join(templates_dir, 'accounts.html')
|
242 |
-
|
243 |
-
with open(index_html_path, 'w') as f:
|
244 |
-
f.write('''
|
245 |
-
<!DOCTYPE html>
|
246 |
-
<html lang="fr">
|
247 |
-
<head>
|
248 |
-
<meta charset="UTF-8">
|
249 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
250 |
-
<title>Générateur de comptes automatique</title>
|
251 |
-
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
|
252 |
-
<style>
|
253 |
-
body { background-color: #f5f5f5; }
|
254 |
-
.card { box-shadow: 0 4px 8px rgba(0,0,0,0.1); }
|
255 |
-
.progress { height: 25px; }
|
256 |
-
#status-display { height: 200px; overflow-y: auto; }
|
257 |
-
</style>
|
258 |
-
</head>
|
259 |
-
<body>
|
260 |
-
<div class="container mt-5">
|
261 |
-
<div class="row">
|
262 |
-
<div class="col-md-12 mb-4">
|
263 |
-
<div class="card">
|
264 |
-
<div class="card-header bg-primary text-white">
|
265 |
-
<h3 class="card-title mb-0">Générateur de comptes - Startup Côte d'Ivoire</h3>
|
266 |
-
</div>
|
267 |
-
<div class="card-body">
|
268 |
-
<form id="generator-form">
|
269 |
-
<div class="row mb-3">
|
270 |
-
<div class="col-md-6">
|
271 |
-
<label for="num_accounts" class="form-label">Nombre de comptes à créer</label>
|
272 |
-
<input type="number" class="form-control" id="num_accounts" name="num_accounts" min="1" max="1000" value="10">
|
273 |
-
</div>
|
274 |
-
<div class="col-md-6">
|
275 |
-
<label for="startup_ratio" class="form-label">Ratio de représentants de startup (%)</label>
|
276 |
-
<input type="number" class="form-control" id="startup_ratio" name="startup_ratio" min="0" max="100" value="30">
|
277 |
-
</div>
|
278 |
-
</div>
|
279 |
-
<div class="d-grid gap-2 d-md-flex justify-content-md-center">
|
280 |
-
<button type="submit" id="start-btn" class="btn btn-success btn-lg">
|
281 |
-
<i class="fas fa-play"></i> Démarrer
|
282 |
-
</button>
|
283 |
-
<button type="button" id="stop-btn" class="btn btn-danger btn-lg">
|
284 |
-
<i class="fas fa-stop"></i> Arrêter
|
285 |
-
</button>
|
286 |
-
<a href="/accounts" class="btn btn-primary btn-lg">
|
287 |
-
<i class="fas fa-list"></i> Voir les comptes
|
288 |
-
</a>
|
289 |
-
</div>
|
290 |
-
</form>
|
291 |
-
</div>
|
292 |
-
</div>
|
293 |
-
</div>
|
294 |
-
|
295 |
-
<div class="col-md-12">
|
296 |
-
<div class="card">
|
297 |
-
<div class="card-header bg-info text-white">
|
298 |
-
<h4 class="card-title mb-0">Progression</h4>
|
299 |
-
</div>
|
300 |
-
<div class="card-body">
|
301 |
-
<div class="progress mb-3">
|
302 |
-
<div id="progress-bar" class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 0%">0%</div>
|
303 |
-
</div>
|
304 |
-
|
305 |
-
<div class="row text-center mb-3">
|
306 |
-
<div class="col">
|
307 |
-
<div class="card bg-light">
|
308 |
-
<div class="card-body">
|
309 |
-
<h5>Total</h5>
|
310 |
-
<h3 id="total-count">0</h3>
|
311 |
-
</div>
|
312 |
-
</div>
|
313 |
-
</div>
|
314 |
-
<div class="col">
|
315 |
-
<div class="card bg-success text-white">
|
316 |
-
<div class="card-body">
|
317 |
-
<h5>Réussis</h5>
|
318 |
-
<h3 id="success-count">0</h3>
|
319 |
-
</div>
|
320 |
-
</div>
|
321 |
-
</div>
|
322 |
-
<div class="col">
|
323 |
-
<div class="card bg-danger text-white">
|
324 |
-
<div class="card-body">
|
325 |
-
<h5>Échecs</h5>
|
326 |
-
<h3 id="failed-count">0</h3>
|
327 |
-
</div>
|
328 |
-
</div>
|
329 |
-
</div>
|
330 |
-
</div>
|
331 |
-
|
332 |
-
<div class="card mb-3">
|
333 |
-
<div class="card-header">
|
334 |
-
<h5>Dernier statut</h5>
|
335 |
-
</div>
|
336 |
-
<div class="card-body">
|
337 |
-
<p id="last-status">-</p>
|
338 |
-
<p>Dernier compte créé: <span id="last-username" class="text-primary fw-bold">-</span></p>
|
339 |
-
</div>
|
340 |
-
</div>
|
341 |
-
|
342 |
-
<div class="row">
|
343 |
-
<div class="col-md-6">
|
344 |
-
<p>Heure de début: <span id="start-time">-</span></p>
|
345 |
-
</div>
|
346 |
-
<div class="col-md-6 text-end">
|
347 |
-
<p>Heure de fin: <span id="end-time">-</span></p>
|
348 |
-
</div>
|
349 |
-
</div>
|
350 |
-
</div>
|
351 |
-
</div>
|
352 |
-
</div>
|
353 |
-
</div>
|
354 |
-
</div>
|
355 |
-
|
356 |
-
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
|
357 |
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/js/all.min.js"></script>
|
358 |
-
<script>
|
359 |
-
document.addEventListener('DOMContentLoaded', function() {
|
360 |
-
// Formulaire de génération
|
361 |
-
document.getElementById('generator-form').addEventListener('submit', function(e) {
|
362 |
-
e.preventDefault();
|
363 |
-
|
364 |
-
const numAccounts = document.getElementById('num_accounts').value;
|
365 |
-
const startupRatio = document.getElementById('startup_ratio').value / 100;
|
366 |
-
|
367 |
-
fetch('/start', {
|
368 |
-
method: 'POST',
|
369 |
-
headers: {
|
370 |
-
'Content-Type': 'application/x-www-form-urlencoded',
|
371 |
-
},
|
372 |
-
body: `num_accounts=${numAccounts}&startup_ratio=${startupRatio}`
|
373 |
-
})
|
374 |
-
.then(response => response.json())
|
375 |
-
.then(data => {
|
376 |
-
if (data.status === 'success') {
|
377 |
-
startProgressUpdates();
|
378 |
-
} else {
|
379 |
-
alert(data.message);
|
380 |
-
}
|
381 |
-
});
|
382 |
-
});
|
383 |
-
|
384 |
-
// Bouton d'arrêt
|
385 |
-
document.getElementById('stop-btn').addEventListener('click', function() {
|
386 |
-
fetch('/stop', {
|
387 |
-
method: 'POST'
|
388 |
-
})
|
389 |
-
.then(response => response.json())
|
390 |
-
.then(data => {
|
391 |
-
alert(data.message);
|
392 |
-
});
|
393 |
-
});
|
394 |
-
|
395 |
-
// Mettre à jour la progression
|
396 |
-
function updateProgress() {
|
397 |
-
fetch('/progress')
|
398 |
-
.then(response => response.json())
|
399 |
-
.then(data => {
|
400 |
-
const progressPercent = data.total > 0 ? Math.round((data.current / data.total) * 100) : 0;
|
401 |
-
|
402 |
-
document.getElementById('progress-bar').style.width = `${progressPercent}%`;
|
403 |
-
document.getElementById('progress-bar').textContent = `${progressPercent}%`;
|
404 |
-
|
405 |
-
document.getElementById('total-count').textContent = data.total;
|
406 |
-
document.getElementById('success-count').textContent = data.success;
|
407 |
-
document.getElementById('failed-count').textContent = data.failed;
|
408 |
-
|
409 |
-
document.getElementById('last-status').textContent = data.last_status;
|
410 |
-
document.getElementById('last-username').textContent = data.last_username || '-';
|
411 |
-
|
412 |
-
document.getElementById('start-time').textContent = data.start_time || '-';
|
413 |
-
document.getElementById('end-time').textContent = data.end_time || '-';
|
414 |
-
});
|
415 |
-
}
|
416 |
-
|
417 |
-
let progressInterval;
|
418 |
-
|
419 |
-
function startProgressUpdates() {
|
420 |
-
// Arrêter l'intervalle précédent s'il existe
|
421 |
-
if (progressInterval) {
|
422 |
-
clearInterval(progressInterval);
|
423 |
-
}
|
424 |
-
|
425 |
-
// Mettre à jour immédiatement
|
426 |
-
updateProgress();
|
427 |
-
|
428 |
-
// Puis toutes les 2 secondes
|
429 |
-
progressInterval = setInterval(updateProgress, 2000);
|
430 |
-
}
|
431 |
-
|
432 |
-
// Vérifier si une génération est déjà en cours au chargement de la page
|
433 |
-
updateProgress();
|
434 |
-
});
|
435 |
-
</script>
|
436 |
-
</body>
|
437 |
-
</html>
|
438 |
-
''')
|
439 |
-
|
440 |
-
with open(accounts_html_path, 'w') as f:
|
441 |
-
f.write('''
|
442 |
-
<!DOCTYPE html>
|
443 |
-
<html lang="fr">
|
444 |
-
<head>
|
445 |
-
<meta charset="UTF-8">
|
446 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
447 |
-
<title>Liste des comptes générés</title>
|
448 |
-
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
|
449 |
-
<style>
|
450 |
-
body { background-color: #f5f5f5; }
|
451 |
-
.card { box-shadow: 0 4px 8px rgba(0,0,0,0.1); }
|
452 |
-
.username-cell {
|
453 |
-
max-width: 200px;
|
454 |
-
overflow: hidden;
|
455 |
-
text-overflow: ellipsis;
|
456 |
-
white-space: nowrap;
|
457 |
-
}
|
458 |
-
.pagination { margin-bottom: 0; }
|
459 |
-
</style>
|
460 |
-
</head>
|
461 |
-
<body>
|
462 |
-
<div class="container mt-5">
|
463 |
-
<div class="row">
|
464 |
-
<div class="col-md-12 mb-4">
|
465 |
-
<div class="card">
|
466 |
-
<div class="card-header bg-primary text-white d-flex justify-content-between align-items-center">
|
467 |
-
<h3 class="mb-0">Liste des comptes générés</h3>
|
468 |
-
<a href="/" class="btn btn-light">Retour au générateur</a>
|
469 |
-
</div>
|
470 |
-
<div class="card-body">
|
471 |
-
<div class="alert alert-info">
|
472 |
-
Total des comptes générés: {{ total_accounts }}
|
473 |
-
</div>
|
474 |
-
|
475 |
-
<div class="table-responsive">
|
476 |
-
<table class="table table-striped table-hover">
|
477 |
-
<thead>
|
478 |
-
<tr>
|
479 |
-
<th>#</th>
|
480 |
-
<th>Nom d'utilisateur</th>
|
481 |
-
<th>Email</th>
|
482 |
-
<th>Mot de passe</th>
|
483 |
-
<th>Startup Rep</th>
|
484 |
-
<th>Date de création</th>
|
485 |
-
<th>Statut</th>
|
486 |
-
</tr>
|
487 |
-
</thead>
|
488 |
-
<tbody>
|
489 |
-
{% for account in accounts %}
|
490 |
-
<tr>
|
491 |
-
<td>{{ (page - 1) * 20 + loop.index }}</td>
|
492 |
-
<td class="username-cell" title="{{ account.username }}">{{ account.username }}</td>
|
493 |
-
<td>{{ account.email }}</td>
|
494 |
-
<td>{{ account.password }}</td>
|
495 |
-
<td>{% if account.is_startup_rep %}Oui{% else %}Non{% endif %}</td>
|
496 |
-
<td>{{ account.created_at }}</td>
|
497 |
-
<td>
|
498 |
-
{% if account.success %}
|
499 |
-
<span class="badge bg-success">Succès</span>
|
500 |
-
{% else %}
|
501 |
-
<span class="badge bg-danger">Échec</span>
|
502 |
-
{% endif %}
|
503 |
-
</td>
|
504 |
-
</tr>
|
505 |
-
{% endfor %}
|
506 |
-
</tbody>
|
507 |
-
</table>
|
508 |
-
</div>
|
509 |
-
|
510 |
-
{% if total_pages > 1 %}
|
511 |
-
<div class="d-flex justify-content-center mt-4">
|
512 |
-
<nav aria-label="Page navigation">
|
513 |
-
<ul class="pagination">
|
514 |
-
<li class="page-item {% if page == 1 %}disabled{% endif %}">
|
515 |
-
<a class="page-link" href="{{ url_for('view_accounts', page=page-1) if page > 1 else '#' }}">Précédent</a>
|
516 |
-
</li>
|
517 |
-
|
518 |
-
{% for p in range(1, total_pages + 1) %}
|
519 |
-
{% if p == page %}
|
520 |
-
<li class="page-item active"><span class="page-link">{{ p }}</span></li>
|
521 |
-
{% else %}
|
522 |
-
<li class="page-item"><a class="page-link" href="{{ url_for('view_accounts', page=p) }}">{{ p }}</a></li>
|
523 |
-
{% endif %}
|
524 |
-
{% endfor %}
|
525 |
-
|
526 |
-
<li class="page-item {% if page == total_pages %}disabled{% endif %}">
|
527 |
-
<a class="page-link" href="{{ url_for('view_accounts', page=page+1) if page < total_pages else '#' }}">Suivant</a>
|
528 |
-
</li>
|
529 |
-
</ul>
|
530 |
-
</nav>
|
531 |
-
</div>
|
532 |
-
{% endif %}
|
533 |
-
</div>
|
534 |
-
</div>
|
535 |
-
</div>
|
536 |
-
</div>
|
537 |
-
</div>
|
538 |
-
|
539 |
-
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
|
540 |
-
</body>
|
541 |
-
</html>
|
542 |
-
''')
|
543 |
|
|
|
544 |
app.run(debug=True)
|
|
|
|
|
1 |
from flask import Flask, render_template, request, jsonify, redirect, url_for
|
2 |
import requests
|
3 |
from bs4 import BeautifulSoup
|
|
|
226 |
total_accounts=total_accounts
|
227 |
)
|
228 |
|
|
|
|
|
|
|
229 |
|
230 |
+
@app.route('/script.js')
|
231 |
+
def serve_js():
|
232 |
+
return render_template('script.js'), 200, {'Content-Type': 'application/javascript'}
|
|
|
233 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
234 |
|
235 |
+
if __name__ == '__main__':
|
236 |
app.run(debug=True)
|