SIA / app.py
analist's picture
Update app.py
4aa378d verified
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)