from flask import Flask, render_template, redirect, url_for, request import csv import telegram from dotenv import load_dotenv import os load_dotenv() app = Flask(__name__) # Configuration Telegram TELEGRAM_TOKEN = "7126991043:AAEzeKswNo6eO7oJA49Hxn_bsbzgzUoJ-6A" # Votre jeton de bot Telegram TELEGRAM_CHAT_ID = "-1002081124539" # L'identifiant du groupe bot = telegram.Bot(token=TELEGRAM_TOKEN) # Chargement du dataset de traductions def load_translations(filename): translations = [] with open(filename, 'r', encoding='utf-8') as file: reader = csv.DictReader(file) for i, row in enumerate(reader): translations.append({ "id": i, "fr": row["fr"], "yi": row["yi"], "likes": 0, "dislikes": 0, "feedback_sent": False }) return translations translations = load_translations('translations.csv') # Votre dataset au format csv @app.route('/') def index(): return render_template('index.html', translations=translations) @app.route('/vote//') def vote(id, action): translation = next((t for t in translations if t["id"] == id), None) if translation: if action == "like": translation["likes"] += 1 elif action == "dislike": translation["dislikes"] += 1 return redirect(url_for('index')) @app.route('/submit_feedback/', methods=['POST']) def submit_feedback(id): translation = next((t for t in translations if t["id"] == id), None) if translation and not translation["feedback_sent"]: feedback = request.form['feedback'] message = f"Feedback sur la traduction #{translation['id']}:\n\n" \ f"Français: {translation['fr']}\n\n" \ f"Yipunu: {translation['yi']}\n\n" \ f"Avis de l'utilisateur:\n{feedback}" bot.send_message(chat_id=TELEGRAM_CHAT_ID, text=message) translation["feedback_sent"] = True return redirect(url_for('index')) if __name__ == '__main__': app.run(debug=True)