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