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 = """ Statut d'enregistrement

Bonjour {{ name }} !

Status: {{ status }}

Email: {{ email }}

Téléphone: {{ phone }}

Enregistré depuis: {{ timestamp }}

""" 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=alice@example.com" email = urllib.parse.unquote(email) return render_status_page(email) @app.route("/person/") 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)