DmitrMakeev commited on
Commit
8477631
·
verified ·
1 Parent(s): fb64302

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -25
app.py CHANGED
@@ -100,32 +100,18 @@ app.config['DEBUG'] = True
100
 
101
 
102
  # Токен Telegram бота
103
- @app.route('/bt_test', methods=['GET', 'POST'])
104
- def bt_test():
105
- if request.method == 'POST':
106
- if 'product_name' in request.form:
107
- product_name = request.form['product_name']
108
- send_to_telegram(product_name)
109
- return redirect(url_for('bt_test'))
110
- else:
111
- return 'No product name provided', 400 # Возвращаем ошибку если нет имени продукта
112
-
113
- return render_template('bt_test.html')
114
-
115
- def send_to_telegram(product_name):
116
- bot_token = '7766407698:AAGZHEbUuiOri4_YzZ7hDPSD6U8MGMXXSnA'
117
- chat_id = '1343658673'
118
- message = f'Новый продукт добавлен: {product_name}'
119
-
120
  try:
121
- response = requests.get(f'https://api.telegram.org/bot{bot_token}/sendMessage', params={
122
- 'chat_id': chat_id,
123
- 'text': message
124
- })
125
- response.raise_for_status() # Проверяем успешность запроса
126
- except requests.exceptions.RequestException as e:
127
- print(f'Error sending message to Telegram: {e}')
128
-
129
 
130
 
131
 
 
100
 
101
 
102
  # Токен Telegram бота
103
+ # Прямой запрос по вашей ссылке
104
+ @app.before_first_request
105
+ def send_initial_request():
106
+ url = "https://api.telegram.org/bot7766407698:AAGZHEbUuiOri4_YzZ7hDPSD6U8MGMXXSnA/sendMessage?chat_id=1343658673&text=%D0%9D%D0%BE%D0%B2%D0%BE%D0%B9+%D0%BF%D1%80%D0%BE%D0%B4%D1%83%D0%BA%D1%82+%D0%B4%D0%BE%D0%B1%D0%B0%D0%B2%D0%BB%D0%B5%D0%BD"
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  try:
108
+ response = requests.get(url)
109
+ if response.status_code == 200:
110
+ print("Сообщение отправлено успешно!")
111
+ else:
112
+ print(f"Ошибка отправки сообщения: {response.status_code}")
113
+ except Exception as e:
114
+ print(f"Ошибка при отправке запроса: {e}")
 
115
 
116
 
117