Update app.py
Browse files
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 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
}
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
@media (max-width: 600px) {
|
45 |
body {
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
}
|
48 |
.container {
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
}
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
{
|
64 |
-
|
65 |
-
<p
|
66 |
-
|
67 |
-
|
68 |
-
</body>
|
69 |
-
</html>
|
70 |
-
"""
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
email = request.args.get("email")
|
75 |
-
|
|
|
|
|
|
|
76 |
|
77 |
-
if not os.path.exists(CSV_FILE):
|
78 |
-
return "Fichier CSV non trouvé."
|
79 |
|
80 |
-
|
|
|
|
|
|
|
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__ ==
|
114 |
-
app.run(
|
|
|
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)
|