Телеграм Бот (Исправленный)

This commit is contained in:
Dronminator
2023-04-15 19:40:02 +03:00
parent 775a3f58a5
commit b50a1dccf5
2 changed files with 5 additions and 4 deletions
+3 -2
View File
@@ -1,7 +1,8 @@
import telebot
import psycopg2
import config
def execute_request(request):
connection = psycopg2.connect(host='localhost', dbname='dbdata', user='postgres', password='Q1w2e3r4')
connection = psycopg2.connect(host=config.host, dbname=config.dbname, user=config.user, password=config.password)
cursor = connection.cursor()
cursor.execute(request)
result = cursor.fetchall()
@@ -9,7 +10,7 @@ def execute_request(request):
connection.close()
return result
max_id = int(execute_request("select count(*) from laptops")[0][0])
bot = telebot.TeleBot('5656574233:AAEU1Ggc4J1aWMtlLnphtScDd3jGCrzbuuY')
bot = telebot.TeleBot(config.bot_token)
@bot.message_handler(commands=["start"])
def start(m, res=False):
bot.send_message(m.chat.id, f'Привет. Введите идентификатор от 1 до {max_id}, чтобы получить данные: ')