Docfile commited on
Commit
de7e336
1 Parent(s): 1f32bb5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -1,19 +1,17 @@
1
  from flask import Flask, render_template, redirect, url_for, request
2
  import csv
3
- import telegram
4
- from dotenv import load_dotenv
5
  import os
 
6
 
7
  load_dotenv()
8
 
9
  app = Flask(__name__)
10
 
11
  # Configuration Telegram
12
- TELEGRAM_TOKEN = "7126991043:AAEzeKswNo6eO7oJA49Hxn_bsbzgzUoJ-6A" # Votre jeton de bot Telegram
13
- TELEGRAM_CHAT_ID = "-1002081124539" # L'identifiant du groupe
14
-
15
- bot = telegram.Bot(token=TELEGRAM_TOKEN)
16
-
17
 
18
  # Chargement du dataset de traductions
19
  def load_translations(filename):
@@ -33,12 +31,10 @@ def load_translations(filename):
33
 
34
  translations = load_translations('translations.csv') # Votre dataset au format csv
35
 
36
-
37
  @app.route('/')
38
  def index():
39
  return render_template('index.html', translations=translations)
40
 
41
-
42
  @app.route('/vote/<int:id>/<string:action>')
43
  def vote(id, action):
44
  translation = next((t for t in translations if t["id"] == id), None)
@@ -49,7 +45,6 @@ def vote(id, action):
49
  translation["dislikes"] += 1
50
  return redirect(url_for('index'))
51
 
52
-
53
  @app.route('/submit_feedback/<int:id>', methods=['POST'])
54
  def submit_feedback(id):
55
  translation = next((t for t in translations if t["id"] == id), None)
@@ -59,8 +54,17 @@ def submit_feedback(id):
59
  f"Français: {translation['fr']}\n\n" \
60
  f"Yipunu: {translation['yi']}\n\n" \
61
  f"Avis de l'utilisateur:\n{feedback}"
62
- bot.send_message(chat_id=TELEGRAM_CHAT_ID, text=message)
63
- translation["feedback_sent"] = True
 
 
 
 
 
 
 
 
 
64
  return redirect(url_for('index'))
65
 
66
 
 
1
  from flask import Flask, render_template, redirect, url_for, request
2
  import csv
3
+ import requests
 
4
  import os
5
+ from dotenv import load_dotenv
6
 
7
  load_dotenv()
8
 
9
  app = Flask(__name__)
10
 
11
  # Configuration Telegram
12
+ BOT_TOKEN = os.getenv("BOT_TOKEN")
13
+ CHAT_ID = os.getenv("CHAT_ID")
14
+ TELEGRAM_API_URL = f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage"
 
 
15
 
16
  # Chargement du dataset de traductions
17
  def load_translations(filename):
 
31
 
32
  translations = load_translations('translations.csv') # Votre dataset au format csv
33
 
 
34
  @app.route('/')
35
  def index():
36
  return render_template('index.html', translations=translations)
37
 
 
38
  @app.route('/vote/<int:id>/<string:action>')
39
  def vote(id, action):
40
  translation = next((t for t in translations if t["id"] == id), None)
 
45
  translation["dislikes"] += 1
46
  return redirect(url_for('index'))
47
 
 
48
  @app.route('/submit_feedback/<int:id>', methods=['POST'])
49
  def submit_feedback(id):
50
  translation = next((t for t in translations if t["id"] == id), None)
 
54
  f"Français: {translation['fr']}\n\n" \
55
  f"Yipunu: {translation['yi']}\n\n" \
56
  f"Avis de l'utilisateur:\n{feedback}"
57
+ params = {
58
+ "chat_id": CHAT_ID,
59
+ "text": message,
60
+ "parse_mode": "HTML"
61
+ }
62
+ response = requests.post(TELEGRAM_API_URL, params=params)
63
+ if response.status_code == 200:
64
+ translation["feedback_sent"] = True
65
+ else:
66
+ print(f"Error sending message to Telegram. Status code: {response.status_code}, Response: {response.text}")
67
+
68
  return redirect(url_for('index'))
69
 
70