Update app.py
Browse files
app.py
CHANGED
@@ -110,9 +110,6 @@ app.config['DEBUG'] = True
|
|
110 |
|
111 |
|
112 |
# Токен Telegram бота
|
113 |
-
API_TOKEN = '7766407698:AAGZHEbUuiOri4_YzZ7hDPSD6U8MGMXXSnA'
|
114 |
-
|
115 |
-
|
116 |
@app.route('/bt_test', methods=['GET', 'POST'])
|
117 |
def bt_test():
|
118 |
if request.method == 'POST':
|
@@ -120,17 +117,24 @@ def bt_test():
|
|
120 |
product_name = request.form['product_name']
|
121 |
send_to_telegram(product_name)
|
122 |
return redirect(url_for('bt_test'))
|
123 |
-
|
124 |
else:
|
125 |
-
return 'No product name provided'
|
|
|
126 |
return render_template('bt_test.html')
|
127 |
|
128 |
def send_to_telegram(product_name):
|
129 |
bot_token = '7766407698:AAGZHEbUuiOri4_YzZ7hDPSD6U8MGMXXSnA'
|
130 |
chat_id = '1343658673'
|
131 |
message = f'Новый продукт добавлен: {product_name}'
|
132 |
-
requests.get(f'https://api.telegram.org/bot{bot_token}/sendMessage?chat_id={chat_id}&text={message}')
|
133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
|
136 |
|
|
|
110 |
|
111 |
|
112 |
# Токен Telegram бота
|
|
|
|
|
|
|
113 |
@app.route('/bt_test', methods=['GET', 'POST'])
|
114 |
def bt_test():
|
115 |
if request.method == 'POST':
|
|
|
117 |
product_name = request.form['product_name']
|
118 |
send_to_telegram(product_name)
|
119 |
return redirect(url_for('bt_test'))
|
|
|
120 |
else:
|
121 |
+
return 'No product name provided', 400 # Возвращаем ошибку если нет имени продукта
|
122 |
+
|
123 |
return render_template('bt_test.html')
|
124 |
|
125 |
def send_to_telegram(product_name):
|
126 |
bot_token = '7766407698:AAGZHEbUuiOri4_YzZ7hDPSD6U8MGMXXSnA'
|
127 |
chat_id = '1343658673'
|
128 |
message = f'Новый продукт добавлен: {product_name}'
|
|
|
129 |
|
130 |
+
try:
|
131 |
+
response = requests.get(f'https://api.telegram.org/bot{bot_token}/sendMessage', params={
|
132 |
+
'chat_id': chat_id,
|
133 |
+
'text': message
|
134 |
+
})
|
135 |
+
response.raise_for_status() # Проверяем успешность запроса
|
136 |
+
except requests.exceptions.RequestException as e:
|
137 |
+
print(f'Error sending message to Telegram: {e}')
|
138 |
|
139 |
|
140 |
|