diff --git a/Задания/task1/Markovich/db.py b/Задания/task1/Markovich/db.py new file mode 100644 index 0000000..e5f1c19 --- /dev/null +++ b/Задания/task1/Markovich/db.py @@ -0,0 +1,49 @@ +import telebot +import psycopg2 +from telebot import types +import random + +connection = psycopg2.connect(dbname='dbdata', user='postgres',password='Q1w2e3r4', host='localhost') +cursor = connection.cursor() + + +sel_query = """SELECT * FROM public.pizza""" +cursor.execute(sel_query) +array = list(cursor.fetchall()) + +bot = telebot.TeleBot('6161398146:AAEY99Cox8omow3OnURN_mwXDOpAOfTp09w') + +@bot.message_handler(commands=["start"]) +def start(m, res=False): + markup = types.ReplyKeyboardMarkup(resize_keyboard=True) + item1 = types.KeyboardButton("Хочу пирог!") + item2 = types.KeyboardButton("Какова цена?") + item3 = types.KeyboardButton("Описание") + markup.add(item1) + markup.add(item2) + markup.add(item3) + bot.send_message( + m.chat.id, '"Хочу пирог!" - для получения пирога\n "Какова цена?" - для получения цены\n "Описание" - описание', + reply_markup=markup) + +i = random.choice(array) +@bot.message_handler(content_types=["text"]) +def handle_text(message): + if (message.text.strip() == 'Хочу пирог!'): + ans = f'{i[1]}\n' + bot.send_message(message.chat.id, ans) + try: + bot.send_photo(message.chat.id, open(i[4], 'rb')) + except telebot.apihelper.ApiTelegramException: + bot.send_message(message.chat.id, "Проблемы с загрузкой картинки....Продолжайте") + elif (message.text.strip() == 'Какова цена?'): + ans = f'{i[3]}\n' + bot.send_message(message.chat.id, ans) + elif (message.text.strip() == 'Описание'): + ans = f'{i[2]}\n' + bot.send_message(message.chat.id, ans) + +bot.polling(none_stop=True, interval=0) + +cursor.close() +connection.close() \ No newline at end of file diff --git a/Задания/task1/Uskova/DataBaze.py b/Задания/task1/Uskova/DataBaze.py index bdd3ded..87851d1 100644 --- a/Задания/task1/Uskova/DataBaze.py +++ b/Задания/task1/Uskova/DataBaze.py @@ -4,36 +4,32 @@ from selenium.webdriver.chrome.service import Service import psycopg2 import wget +browser = webdriver.Chrome(service=Service('C:\\Users\\Yekaterina\\Downloads\\chromedriver_win32.zip\\chromedriver.exe')) +browser.get('https://msk.sushi-market.com/menu/rolly') +soup = BeautifulSoup(browser.page_source, "lxml") + +Name = soup.find_all(attrs={"class": "goodsBlockName device-show"}) +Info = soup.find_all(attrs={"class": "goodsBlockWeight"}) +Des = soup.find_all(attrs={"class": "cardsList_text"}) +Price = soup.find_all(attrs={"class": "product__price updated"}) +Image = soup.find_all(attrs={"class": "cardsList_img add-to-cart__img"}) + connection = psycopg2.connect(host='localhost', dbname='dbdata', user='postgres', password='Q1w2e3r4') cursor = connection.cursor() - -crtable = """ create table Notebooks - (id serial primary key, name varchar(500), description varchar(500), code varchar(200), price varchar(100), - picture varchar(500)) """ - -cursor.execute(crtable) +create_q = '''CREATE TABLE F0ood (ID serial primary key, Name varchar(5000), Info varchar(5000), Des varchar(10000), Price varchar(600), src varchar(1000))''' +cursor.execute(create_q) connection.commit() -s = Service('C:\\Users\\Yekaterina\\Downloads\\chromedriver_win32\\chromedriver.exe') -browser = webdriver.Chrome(service=s) -browser.get('https://www.citilink.ru/catalog/noutbuki/') -html_text = browser.page_source -soup = BeautifulSoup(html_text, 'lxml') +for j in range(25): + url = Image[j].find('img').attrs['src'] + tempf = f"img\\food{j}.jpg" + wget.download(url, tempf) + insert_query = f'''INSERT into public.F0ood(Name, Info, Des, Price, src) values ('{Name[j].text}','{Info[j].text}','{Des[j].text}', '{Price[j].text}', '{tempf}') ''' + cursor.execute(insert_query) +connection.commit() -name = soup.find_all('div', class_='app-catalog-1tp0ino e1an64qs0') -description = soup.find_all('div', class_='app-catalog-1o4umte eevw8x70') -code = soup.find_all('div', class_= 'app-catalog-0 e1dsj6g20') -price = soup.find_all('div', class_= 'app-catalog-0 e1dsj6g20') -picture = soup.find_all('div', class_='app-catalog-0 e1jarwcz0') - -for i in range(len(name)): - url = picture[i].find('img').attrs['src'] - file = f"C:\\Users\\Yekaterina\\Desktop\\baza\\pic{i}.JPG" - wget.download(url, file) - ins_qwery = f"""insert into public.Notebooks(name, description, code, price, picture) - values ('{name[i].text}', '{description[i].text}', '{code[i].text}', '{price[i].text}','{file}')""" - cursor.execute(ins_qwery) - connection.commit() +cursor.execute("SELECT * from F0ood") +print(cursor.fetchall()) cursor.close() connection.close() 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) diff --git a/Задания/task1/Uskova/parcing.py b/Задания/task1/Uskova/parcing.py index 17aeb52..5c406ad 100644 --- a/Задания/task1/Uskova/parcing.py +++ b/Задания/task1/Uskova/parcing.py @@ -8,7 +8,9 @@ browser = webdriver.Chrome(service=s) browser.get('https://www.citilink.ru/catalog/noutbuki/') html_text = browser.page_source soup = BeautifulSoup(html_text, 'lxml') + + name=soup.find_all('div', class_='app-catalog-1tp0ino e1an64qs0') -print (name[0].text) +print (name[1].text) description=soup.find_all('div', class_='app-catalog-1o4umte eevw8x70') -print (description[0].text) +print (description[1].text)