File size: 2,086 Bytes
0eae3d6
fe5005f
e218737
c3883a9
de7e336
c3883a9
fe5005f
 
c3883a9
 
e218737
 
 
fe5005f
 
 
 
 
 
 
 
 
 
 
 
0eae3d6
 
fe5005f
c3883a9
e218737
eae4b54
 
 
 
 
 
 
c8cb35b
0c088e6
eae4b54
 
 
 
 
e218737
c3883a9
eae4b54
 
 
fe5005f
 
 
c3883a9
1fde53e
0489bc9
eae4b54
e218737
fe5005f
 
 
 
 
 
 
 
e218737
 
fe5005f
612150f
e218737
fe5005f
 
0eae3d6
612150f
 
fe5005f
ef81ad8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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/<int:id>/<string:action>')
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/<int:id>', methods=['POST'])
def submit_feedback(id):
     return redirect(url_for('index'))


if __name__ == '__main__':
    app.run(debug=True)