analist commited on
Commit
4aa378d
·
verified ·
1 Parent(s): 13a71f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +97 -96
app.py CHANGED
@@ -2,113 +2,114 @@ 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)
 
2
  import pandas as pd
3
  from datetime import datetime
4
  import os
5
+ import urllib.parse
6
 
7
  app = Flask(__name__)
8
 
9
  CSV_FILE = "people.csv"
10
 
11
+ def load_data():
12
+ if not os.path.exists(CSV_FILE):
13
+ df = pd.DataFrame(columns=['email', 'name', 'registered', 'phone', 'timestamp'])
14
+ df.to_csv(CSV_FILE, index=False)
15
+ return pd.read_csv(CSV_FILE)
16
+
17
+ def save_data(df):
18
+ df.to_csv(CSV_FILE, index=False)
19
+
20
+ def render_status_page(email):
21
+ df = load_data()
22
+
23
+ if email not in df['email'].values:
24
+ return f"L'email {email} n'est pas dans la liste."
25
+
26
+ idx = df.index[df['email'] == email][0]
27
+ if not df.at[idx, 'registered']:
28
+ df.at[idx, 'registered'] = True
29
+ df.at[idx, 'timestamp'] = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
30
+ save_data(df)
31
+ status = "✅ Enregistré avec succès !"
32
+ else:
33
+ status = "✅ Vous êtes déjà enregistré."
34
+
35
+ person = df.loc[idx]
36
+
37
+ html = """
38
+ <!DOCTYPE html>
39
+ <html lang="fr">
40
+ <head>
41
+ <meta charset="UTF-8" />
42
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
43
+ <title>Statut d'enregistrement</title>
44
+ <style>
 
45
  body {
46
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
47
+ Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
48
+ background-color: #f5f7fa;
49
+ color: #333;
50
+ margin: 0; padding: 0;
51
+ display: flex;
52
+ justify-content: center;
53
+ align-items: center;
54
+ height: 100vh;
55
  }
56
  .container {
57
+ background: white;
58
+ padding: 2rem 3rem;
59
+ border-radius: 8px;
60
+ box-shadow: 0 4px 12px rgba(0,0,0,0.1);
61
+ max-width: 400px;
62
+ width: 90%;
63
+ text-align: center;
64
+ }
65
+ h1 {
66
+ color: #2c3e50;
67
+ margin-bottom: 1rem;
68
  }
69
+ p {
70
+ font-size: 1.1rem;
71
+ margin: 0.5rem 0;
72
+ }
73
+ strong {
74
+ color: #27ae60;
75
+ }
76
+ </style>
77
+ </head>
78
+ <body>
79
+ <div class="container">
80
+ <h1>Bonjour {{ name }} !</h1>
81
+ <p>Status: <strong>{{ status }}</strong></p>
82
+ <p>Email: {{ email }}</p>
83
+ <p>Téléphone: {{ phone }}</p>
84
+ <p>Enregistré depuis: {{ timestamp }}</p>
85
+ </div>
86
+ </body>
87
+ </html>
88
+ """
89
+
90
+ return render_template_string(html,
91
+ name=person['name'],
92
+ status=status,
93
+ email=person['email'],
94
+ phone=person['phone'],
95
+ timestamp=person['timestamp'] if 'timestamp' in person and pd.notna(person['timestamp']) else "N/A"
96
+ )
97
+
98
+
99
+ @app.route("/")
100
+ def home():
101
  email = request.args.get("email")
102
+ if not email:
103
+ return "Paramètre email manquant dans l'URL. Exemple: /[email protected]"
104
+ email = urllib.parse.unquote(email)
105
+ return render_status_page(email)
106
 
 
 
107
 
108
+ @app.route("/person/<path:email>")
109
+ def person(email):
110
+ email = urllib.parse.unquote(email) # pour gérer les emails encodés (%40 etc)
111
+ return render_status_page(email)
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
 
114
+ if __name__ == "__main__":
115
+ app.run(host="0.0.0.0", port=7860)