analist commited on
Commit
4ca3337
·
verified ·
1 Parent(s): 6a134ce

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +114 -0
app.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, render_template_string
2
+ import pandas as pd
3
+ from datetime import datetime
4
+ import os
5
+
6
+ app = Flask(__name__)
7
+
8
+ CSV_FILE = "people.csv"
9
+
10
+ HTML_TEMPLATE = """
11
+ <!DOCTYPE html>
12
+ <html lang="fr">
13
+ <head>
14
+ <meta charset="UTF-8">
15
+ <title>Vérification d'enregistrement</title>
16
+ <style>
17
+ body {
18
+ font-family: 'Segoe UI', sans-serif;
19
+ background: linear-gradient(to right, #f8f9fa, #e9ecef);
20
+ text-align: center;
21
+ padding: 2rem;
22
+ color: #212529;
23
+ }
24
+ .container {
25
+ max-width: 600px;
26
+ margin: auto;
27
+ background-color: white;
28
+ padding: 2rem;
29
+ border-radius: 15px;
30
+ box-shadow: 0 4px 10px rgba(0,0,0,0.1);
31
+ }
32
+ h1 {
33
+ color: #007bff;
34
+ }
35
+ .status {
36
+ font-size: 1.5rem;
37
+ margin-top: 1rem;
38
+ }
39
+ .timestamp {
40
+ color: #6c757d;
41
+ font-size: 0.95rem;
42
+ margin-top: 0.5rem;
43
+ }
44
+ @media (max-width: 600px) {
45
+ body {
46
+ padding: 1rem;
47
+ }
48
+ .container {
49
+ padding: 1.5rem;
50
+ }
51
+ }
52
+ </style>
53
+ </head>
54
+ <body>
55
+ <div class="container">
56
+ <h1>Vérification d'enregistrement</h1>
57
+ {% if person %}
58
+ <p><strong>Nom:</strong> {{ person.name }}</p>
59
+ <p><strong>Email:</strong> {{ person.email }}</p>
60
+ <p class="status">{{ status }}</p>
61
+ {% if timestamp %}
62
+ <p class="timestamp">Enregistré le {{ timestamp }}</p>
63
+ {% endif %}
64
+ {% else %}
65
+ <p class="status">❌ Utilisateur non trouvé.</p>
66
+ {% endif %}
67
+ </div>
68
+ </body>
69
+ </html>
70
+ """
71
+
72
+ @app.route('/')
73
+ def check_registration():
74
+ email = request.args.get("email")
75
+ phone = request.args.get("phone")
76
+
77
+ if not os.path.exists(CSV_FILE):
78
+ return "Fichier CSV non trouvé."
79
+
80
+ df = pd.read_csv(CSV_FILE)
81
+
82
+ # Recherche par email ou téléphone
83
+ if email:
84
+ person_row = df[df['email'] == email]
85
+ elif phone:
86
+ person_row = df[df['phone'] == phone]
87
+ else:
88
+ person_row = pd.DataFrame()
89
+
90
+ if not person_row.empty:
91
+ index = person_row.index[0]
92
+ registered = person_row.at[index, "registered"]
93
+
94
+ if not registered:
95
+ # Marquer comme enregistré
96
+ df.at[index, "registered"] = True
97
+ timestamp = datetime.now().strftime("%d/%m/%Y à %Hh%M")
98
+ df.at[index, "timestamp"] = timestamp
99
+ df.to_csv(CSV_FILE, index=False)
100
+ status = "✅ Enregistrement effectué avec succès."
101
+ else:
102
+ timestamp = person_row.at[index, "timestamp"]
103
+ status = "✅ Utilisateur déjà enregistré."
104
+
105
+ person = {
106
+ "name": person_row.at[index, "name"],
107
+ "email": person_row.at[index, "email"]
108
+ }
109
+ return render_template_string(HTML_TEMPLATE, person=person, status=status, timestamp=timestamp)
110
+ else:
111
+ return render_template_string(HTML_TEMPLATE, person=None, status=None, timestamp=None)
112
+
113
+ if __name__ == '__main__':
114
+ app.run(debug=True, host="0.0.0.0", port=8000)