mirror of
https://github.com/KUlishevgeniy/c22712.git
synced 2026-09-23 23:50:21 +00:00
Update bott.py
This commit is contained in:
@@ -1,36 +1,43 @@
|
|||||||
import telebot
|
import telebot
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import config
|
|
||||||
from telebot import types
|
from telebot import types
|
||||||
import random
|
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()
|
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())
|
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"])
|
@bot.message_handler(commands=["start"])
|
||||||
|
|
||||||
def start(m, res=False):
|
def start(m, res=False):
|
||||||
markup=types.ReplyKeyboardMarkup(resize_keyboard=True)
|
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
|
||||||
item1=types.KeyboardButton("Выбери ноутбук")
|
item1 = types.KeyboardButton("Роллы")
|
||||||
item2=types.KeyboardButton("Еще!")
|
item2 = types.KeyboardButton("Хочу еще!")
|
||||||
markup.add(item1)
|
markup.add(item1)
|
||||||
markup.add(item2)
|
markup.add(item2)
|
||||||
bot.send_message(m.chat.id, 'Нажми: \nВыбери ноутбук'
|
bot.send_message(m.chat.id,
|
||||||
' для просмотра товара\nЕще! '
|
'"Роллы" - получите случайную порцию роллов\n'
|
||||||
'— для повтора', reply_markup=markup)
|
' "Хочу еще!" - вдруг вы не наелись', reply_markup=markup)
|
||||||
|
|
||||||
|
i = random.choice(array)
|
||||||
@bot.message_handler(content_types=["text"])
|
@bot.message_handler(content_types=["text"])
|
||||||
def handle_text(message):
|
def handle_text(message):
|
||||||
if message.text.strip() == 'Выбери ноутбук' :
|
global i
|
||||||
q = random.choice(array)
|
if (message.text.strip() == 'Роллы'):
|
||||||
answer = f'Название: {q[1]}\nОписание: {q[2]}\nКод: {q[3]}\nЦена: {q[4]}\n'
|
i = random.choice(array)
|
||||||
bot.send_message(message.chat.id, answer)
|
ans = f'Название: {i[1]}\nГраммы: {i[2]}\nОписание: {i[3]}\nЦена за 4 штуки: {i[4]}\n'
|
||||||
bot.send_picture(message.chat.id, open(q[5], 'rb'))
|
bot.send_message(message.chat.id, ans)
|
||||||
elif message.text.strip() == 'Еще!':
|
bot.send_photo(message.chat.id, open(i[5], 'rb'))
|
||||||
bot.send_message(message.chat.id, 'Ввод: '+ message.text)
|
elif (message.text.strip() == 'Хочу еще!'):
|
||||||
|
bot.send_message(message.chat.id, 'Ввод: ' + message.text)
|
||||||
|
|
||||||
bot.polling(none_stop=True, interval=0)
|
bot.polling(none_stop=True, interval=0)
|
||||||
|
|||||||
Reference in New Issue
Block a user