from flask import Flask, render_template, redirect, url_for, request, jsonify import csv import requests import os from dotenv import load_dotenv load_dotenv() app = Flask(__name__) # Configuration Telegram BOT_TOKEN = "7126991043:AAEzeKswNo6eO7oJA49Hxn_bsbzgzUoJ-6A" CHAT_ID = "-1002081124539" TELEGRAM_API_URL = f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage" # 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, }) return translations translations = load_translations('translations.csv') # Votre dataset au format csv @app.route('/data') def data(): return jsonify(translations=translations) @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: 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}" params = { "chat_id": CHAT_ID, "text": message, "parse_mode": "HTML" } response = requests.post(TELEGRAM_API_URL, params=params) if response.status_code == 200: return jsonify({"message": "Feedback sent succesfully"}) else: print(f"Error sending message to Telegram. Status code: {response.status_code}, Response: {response.text}") return jsonify({"message": "Error sending message to Telegram"}), 500 return redirect(url_for('index')) if __name__ == '__main__': app.run(debug=True)