From abb924fb6c30228c2bd2c2f111de6e48f0127110 Mon Sep 17 00:00:00 2001 From: polevev <124861891+polevev@users.noreply.github.com> Date: Sun, 7 May 2023 16:54:06 +0300 Subject: [PATCH 1/6] Add files via upload --- Задания/task1/Markovich/db.py | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Задания/task1/Markovich/db.py 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 From f985f9b2d54be3b3b6b3ad82625cfc2d7a51b454 Mon Sep 17 00:00:00 2001 From: eauskova <124862140+eauskova@users.noreply.github.com> Date: Tue, 9 May 2023 02:58:15 +0300 Subject: [PATCH 2/6] Update parcing.py --- Задания/task1/Uskova/parcing.py | 43 ++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/Задания/task1/Uskova/parcing.py b/Задания/task1/Uskova/parcing.py index 17aeb52..c989b42 100644 --- a/Задания/task1/Uskova/parcing.py +++ b/Задания/task1/Uskova/parcing.py @@ -1,14 +1,35 @@ from bs4 import BeautifulSoup -from selenium.webdriver import Chrome from selenium import webdriver from selenium.webdriver.chrome.service import Service -import time -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') -name=soup.find_all('div', class_='app-catalog-1tp0ino e1an64qs0') -print (name[0].text) -description=soup.find_all('div', class_='app-catalog-1o4umte eevw8x70') -print (description[0].text) +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": "goodsBlockPrice"}) +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() +create_q = '''CREATE TABLE Food (ID serial primary key, Name varchar(5000), Info varchar(5000), Des varchar(10000), Price varchar(6000), src varchar(1000))''' +cursor.execute(create_q) +connection.commit() + +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.Food(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() + +cursor.execute("SELECT * from Food") +print(cursor.fetchall()) + +cursor.close() +connection.close() From 8a4ba475d02ef456804b595ad1a4c0c3360570c0 Mon Sep 17 00:00:00 2001 From: eauskova <124862140+eauskova@users.noreply.github.com> Date: Tue, 9 May 2023 02:58:51 +0300 Subject: [PATCH 3/6] Update DataBaze.py --- Задания/task1/Uskova/DataBaze.py | 46 +++++++++++++++----------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/Задания/task1/Uskova/DataBaze.py b/Задания/task1/Uskova/DataBaze.py index bdd3ded..c989b42 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": "goodsBlockPrice"}) +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 Food (ID serial primary key, Name varchar(5000), Info varchar(5000), Des varchar(10000), Price varchar(6000), 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.Food(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 Food") +print(cursor.fetchall()) cursor.close() connection.close() From 2e9837fdf4fdfcdd936079b2834dc6cfccf3ba69 Mon Sep 17 00:00:00 2001 From: eauskova <124862140+eauskova@users.noreply.github.com> Date: Tue, 9 May 2023 02:59:26 +0300 Subject: [PATCH 4/6] Update parcing.py --- Задания/task1/Uskova/parcing.py | 41 +++++++++------------------------ 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/Задания/task1/Uskova/parcing.py b/Задания/task1/Uskova/parcing.py index c989b42..5c406ad 100644 --- a/Задания/task1/Uskova/parcing.py +++ b/Задания/task1/Uskova/parcing.py @@ -1,35 +1,16 @@ from bs4 import BeautifulSoup +from selenium.webdriver import Chrome from selenium import webdriver from selenium.webdriver.chrome.service import Service -import psycopg2 -import wget +import time +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') -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": "goodsBlockPrice"}) -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() -create_q = '''CREATE TABLE Food (ID serial primary key, Name varchar(5000), Info varchar(5000), Des varchar(10000), Price varchar(6000), src varchar(1000))''' -cursor.execute(create_q) -connection.commit() - -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.Food(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() - -cursor.execute("SELECT * from Food") -print(cursor.fetchall()) - -cursor.close() -connection.close() +name=soup.find_all('div', class_='app-catalog-1tp0ino e1an64qs0') +print (name[1].text) +description=soup.find_all('div', class_='app-catalog-1o4umte eevw8x70') +print (description[1].text) From ba4992e667f88d967cb3cdab9a85aec0a622ce46 Mon Sep 17 00:00:00 2001 From: eauskova <124862140+eauskova@users.noreply.github.com> Date: Tue, 9 May 2023 03:25:55 +0300 Subject: [PATCH 5/6] Update DataBaze.py --- Задания/task1/Uskova/DataBaze.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Задания/task1/Uskova/DataBaze.py b/Задания/task1/Uskova/DataBaze.py index c989b42..87851d1 100644 --- a/Задания/task1/Uskova/DataBaze.py +++ b/Задания/task1/Uskova/DataBaze.py @@ -11,12 +11,12 @@ 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": "goodsBlockPrice"}) +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() -create_q = '''CREATE TABLE Food (ID serial primary key, Name varchar(5000), Info varchar(5000), Des varchar(10000), Price varchar(6000), src varchar(1000))''' +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() @@ -24,11 +24,11 @@ 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.Food(Name, Info, Des, Price, src) values ('{Name[j].text}','{Info[j].text}','{Des[j].text}', '{Price[j].text}', '{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() -cursor.execute("SELECT * from Food") +cursor.execute("SELECT * from F0ood") print(cursor.fetchall()) cursor.close() From 178b051175bb6d5667511a90f52ecccd4286ae13 Mon Sep 17 00:00:00 2001 From: eauskova <124862140+eauskova@users.noreply.github.com> Date: Tue, 9 May 2023 03:27:04 +0300 Subject: [PATCH 6/6] Update bott.py --- Задания/task1/Uskova/bott.py | 51 ++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 22 deletions(-) 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)