|
from flask import Flask, request, render_template_string |
|
import pandas as pd |
|
from datetime import datetime |
|
import os |
|
|
|
app = Flask(__name__) |
|
|
|
CSV_FILE = "people.csv" |
|
|
|
HTML_TEMPLATE = """ |
|
<!DOCTYPE html> |
|
<html lang="fr"> |
|
<head> |
|
<meta charset="UTF-8"> |
|
<title>Vérification d'enregistrement</title> |
|
<style> |
|
body { |
|
font-family: 'Segoe UI', sans-serif; |
|
background: linear-gradient(to right, #f8f9fa, #e9ecef); |
|
text-align: center; |
|
padding: 2rem; |
|
color: #212529; |
|
} |
|
.container { |
|
max-width: 600px; |
|
margin: auto; |
|
background-color: white; |
|
padding: 2rem; |
|
border-radius: 15px; |
|
box-shadow: 0 4px 10px rgba(0,0,0,0.1); |
|
} |
|
h1 { |
|
color: #007bff; |
|
} |
|
.status { |
|
font-size: 1.5rem; |
|
margin-top: 1rem; |
|
} |
|
.timestamp { |
|
color: #6c757d; |
|
font-size: 0.95rem; |
|
margin-top: 0.5rem; |
|
} |
|
@media (max-width: 600px) { |
|
body { |
|
padding: 1rem; |
|
} |
|
.container { |
|
padding: 1.5rem; |
|
} |
|
} |
|
</style> |
|
</head> |
|
<body> |
|
<div class="container"> |
|
<h1>Vérification d'enregistrement</h1> |
|
{% if person %} |
|
<p><strong>Nom:</strong> {{ person.name }}</p> |
|
<p><strong>Email:</strong> {{ person.email }}</p> |
|
<p class="status">{{ status }}</p> |
|
{% if timestamp %} |
|
<p class="timestamp">Enregistré le {{ timestamp }}</p> |
|
{% endif %} |
|
{% else %} |
|
<p class="status">❌ Utilisateur non trouvé.</p> |
|
{% endif %} |
|
</div> |
|
</body> |
|
</html> |
|
""" |
|
|
|
@app.route('/') |
|
def check_registration(): |
|
email = request.args.get("email") |
|
phone = request.args.get("phone") |
|
|
|
if not os.path.exists(CSV_FILE): |
|
return "Fichier CSV non trouvé." |
|
|
|
df = pd.read_csv(CSV_FILE) |
|
|
|
|
|
if email: |
|
person_row = df[df['email'] == email] |
|
elif phone: |
|
person_row = df[df['phone'] == phone] |
|
else: |
|
person_row = pd.DataFrame() |
|
|
|
if not person_row.empty: |
|
index = person_row.index[0] |
|
registered = person_row.at[index, "registered"] |
|
|
|
if not registered: |
|
|
|
df.at[index, "registered"] = True |
|
timestamp = datetime.now().strftime("%d/%m/%Y à %Hh%M") |
|
df.at[index, "timestamp"] = timestamp |
|
df.to_csv(CSV_FILE, index=False) |
|
status = "✅ Enregistrement effectué avec succès." |
|
else: |
|
timestamp = person_row.at[index, "timestamp"] |
|
status = "✅ Utilisateur déjà enregistré." |
|
|
|
person = { |
|
"name": person_row.at[index, "name"], |
|
"email": person_row.at[index, "email"] |
|
} |
|
return render_template_string(HTML_TEMPLATE, person=person, status=status, timestamp=timestamp) |
|
else: |
|
return render_template_string(HTML_TEMPLATE, person=None, status=None, timestamp=None) |
|
|
|
if __name__ == '__main__': |
|
app.run(debug=True, host="0.0.0.0", port=8000) |
|
|