from flask import Flask, render_template, redirect, url_for, request import csv import requests import os from dotenv import load_dotenv load_dotenv() app = Flask(__name__) # Configuration Telegram # 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 def load_translations_fang(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, "français": row["Français"], "fang": row["Fang"], "likes": 0, "dislikes": 0, "feedback_sent": False }) return translations translations = load_translations('translations.csv') fang_translation = load_translations_fang("fang.csv") @app.route('/') def index(): return render_template('index.html', translations=translations) @app.route('/fangs') def index_fang(): return render_template('fang.html', translations=fang_translation) @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 elif action == "submit": translation["feedback_sent"] = True return redirect(url_for('index')) @app.route('/submit_feedback/', methods=['POST']) def submit_feedback(id): return redirect(url_for('index')) if __name__ == '__main__': app.run(debug=True)