diff --git a/Задания/task1/Uskova/bott.py b/Задания/task1/Uskova/bott.py index 47436e0..4aa410c 100644 --- a/Задания/task1/Uskova/bott.py +++ b/Задания/task1/Uskova/bott.py @@ -1,36 +1,43 @@ import telebot import psycopg2 -import config from telebot import types import random -import tableCreator -connection = psycopg2.connect(host='localhost', dbname='parc', user='postgres', password='Q1w2e3r4') +connection = psycopg2.connect(host='localhost', dbname='dbdata', user='postgres', password='Q1w2e3r4') cursor = connection.cursor() +try: + sel_query = """SELECT * FROM public.f0ood""" + cursor.execute(sel_query) +except psycopg2.errors.UndefinedTable: + connection.rollback() + import problems + sel_query = """SELECT * FROM public.f0ood""" + cursor.execute(sel_query) -ins_query = """SELECT * FROM public.Notebooks""" -cursor.execute(ins_query) array = list(cursor.fetchall()) +bot = telebot.TeleBot('6280771915:AAG2rcsqHZbUjeaOD-llwR-UU-LabMprKBo') -bot = telebot.TeleBot('6205726630:AAF4zfV_P2b0f7bClm__sWuRmoZ1XpiC_xo') @bot.message_handler(commands=["start"]) - def start(m, res=False): - markup=types.ReplyKeyboardMarkup(resize_keyboard=True) - item1=types.KeyboardButton("Выбери ноутбук") - item2=types.KeyboardButton("Еще!") - markup.add(item1) - markup.add(item2) - bot.send_message(m.chat.id, 'Нажми: \nВыбери ноутбук' - ' для просмотра товара\nЕще! ' - '— для повтора', reply_markup=markup) + markup = types.ReplyKeyboardMarkup(resize_keyboard=True) + item1 = types.KeyboardButton("Роллы") + item2 = types.KeyboardButton("Хочу еще!") + markup.add(item1) + markup.add(item2) + bot.send_message(m.chat.id, + '"Роллы" - получите случайную порцию роллов\n' + ' "Хочу еще!" - вдруг вы не наелись', reply_markup=markup) + +i = random.choice(array) @bot.message_handler(content_types=["text"]) def handle_text(message): - if message.text.strip() == 'Выбери ноутбук' : - q = random.choice(array) - answer = f'Название: {q[1]}\nОписание: {q[2]}\nКод: {q[3]}\nЦена: {q[4]}\n' - bot.send_message(message.chat.id, answer) - bot.send_picture(message.chat.id, open(q[5], 'rb')) - elif message.text.strip() == 'Еще!': - bot.send_message(message.chat.id, 'Ввод: '+ message.text) + global i + if (message.text.strip() == 'Роллы'): + i = random.choice(array) + ans = f'Название: {i[1]}\nГраммы: {i[2]}\nОписание: {i[3]}\nЦена за 4 штуки: {i[4]}\n' + bot.send_message(message.chat.id, ans) + bot.send_photo(message.chat.id, open(i[5], 'rb')) + elif (message.text.strip() == 'Хочу еще!'): + bot.send_message(message.chat.id, 'Ввод: ' + message.text) + bot.polling(none_stop=True, interval=0)