mirror of
https://github.com/KUlishevgeniy/c22712.git
synced 2026-09-23 23:50:21 +00:00
Merge branch 'master' of https://github.com/KUlishevgeniy/c22712
This commit is contained in:
@@ -23,6 +23,8 @@ finally:
|
||||
|
||||
bot = telebot.TeleBot('5980905704:AAH2qIP4Gy60nhuKNAojOGpmI6zwNoJK1Iw')
|
||||
|
||||
min_id, max_id = 1, 60
|
||||
|
||||
@bot.message_handler(commands=["start"])
|
||||
def start(m, res=False):
|
||||
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
|
||||
@@ -30,12 +32,14 @@ def start(m, res=False):
|
||||
item2 = types.KeyboardButton("Хочу картинку любых цветов, пожалуйста")
|
||||
item3 = types.KeyboardButton("Хочу информацию о предложении дня, пожалуйста")
|
||||
item4 = types.KeyboardButton("Общая информация о сведениях, находящихся в базе данных")
|
||||
item5 = types.KeyboardButton("Поиск конкретного предложения по ID")
|
||||
markup.add(item1)
|
||||
markup.add(item2)
|
||||
markup.add(item3)
|
||||
markup.add(item4)
|
||||
markup.add(item5)
|
||||
bot.send_message(m.chat.id,
|
||||
'"Хочу информацию о любых цветах, пожалуйста" - для получения карточки цветов;\n "Хочу картинку любых цветов, пожалуйста" - для получения картинки цветов;\n "Хочу информацию о предложении дня, пожалуйста" - сводка о конкретных цветах;\n "Общая информация о сведениях, находящихся в базе данных" - сводка об характеристиках товаров, информация о которых находится в БД.',
|
||||
'"Хочу информацию о любых цветах, пожалуйста" - для получения карточки цветов;\n "Хочу картинку любых цветов, пожалуйста" - для получения картинки цветов;\n "Хочу информацию о предложении дня, пожалуйста" - сводка о конкретных цветах;\n "Общая информация о сведениях, находящихся в базе данных" - сводка об характеристиках товаров, информация о которых находится в БД.\n "Поиск конкретного предложения по ID" - найдите инересующее вас предложение по ID',
|
||||
reply_markup=markup)
|
||||
|
||||
@bot.message_handler(content_types=["text"])
|
||||
@@ -54,9 +58,26 @@ def handle_text(message):
|
||||
bot.send_message(message.chat.id, "Предложение дня:\n")
|
||||
bot.send_message(message.chat.id, a1)
|
||||
bot.send_photo(message.chat.id, open(i[4], 'rb'))
|
||||
elif (message.text.strip() == "Поиск конкретного предложения по ID"):
|
||||
sent = bot.send_message(message.chat.id,
|
||||
f'Введите идентификатор(ID, целое число) от {min_id} до {max_id}, чтобы получить информацию о конкретном предложении: ')
|
||||
bot.register_next_step_handler(sent, ret_id)
|
||||
else:
|
||||
bot.send_message(message.chat.id, "С помощью данного бота вы можете получить информацию о 60-и цветах одного из московских магазинов по их продаже, в частности их: название, цену, скидку(в процентах) и фото. Вы можете это осуществить, взаимодействуя с ботом. Попробуйте! ")
|
||||
|
||||
def ret_id(message):
|
||||
try:
|
||||
now_id = (message.text)
|
||||
now_id = int(float(now_id))
|
||||
z = list(select(now_id))
|
||||
a2 = f'Название: {z[1]};\nЦена: {z[2]};\nСкидка(в процентах): {z[3]};\n'
|
||||
bot.send_message(message.chat.id, a2)
|
||||
bot.send_photo(message.chat.id, open(z[4], 'rb'))
|
||||
bot.send_message(message.chat.id, "Для повторного поиска по ID воспользуйтесь соответствующей кнопкой в 'меню'")
|
||||
except ValueError:
|
||||
bot.send_message(message.chat.id,
|
||||
"По такому ID нет данных. Попробуйте заново через 'меню' кнопок найти интересующее вас предложение")
|
||||
|
||||
bot.polling(none_stop=True, interval=0)
|
||||
|
||||
cursor.close()
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import psycopg2
|
||||
import wget
|
||||
from bs4 import BeautifulSoup
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
|
||||
connection = psycopg2.connect(host='localhost', dbname='dbdata', user='postgres', password='Q1w2e3r4')
|
||||
|
||||
cursor = connection.cursor()
|
||||
|
||||
create_table = """ create table food
|
||||
(id serial primary key, name varchar(200), price varchar(100), gram varchar(100), stock varchar(100))"""
|
||||
|
||||
cursor.execute(create_table)
|
||||
connection.commit()
|
||||
|
||||
driver = Service('C:\\Users\\Honor\\Desktop\\учеба\\прога\\скачали хроме\chromedriver.exe')
|
||||
browser = webdriver.Chrome(service=driver)
|
||||
browser.get('https://vkusvill.ru/goods/gotovaya-eda/')
|
||||
html_code = browser.page_source
|
||||
soup = BeautifulSoup(html_code, 'lxml')
|
||||
|
||||
name = soup.find_all('a', class_="ProductCard__link rtext _desktop-md _mobile-sm gray900 js-datalayer-catalog-list-name")
|
||||
price = soup.find_all('span', class_="Price Price--md Price--label Price--gray")
|
||||
gram = soup.find_all('div', class_="ProductCard__weight rtext _desktop-sm gray500 nobr")
|
||||
stock = soup.find_all('div', class_="Rating__text subtitle _desktop-sm gray900")
|
||||
|
||||
|
||||
for i in range(15):
|
||||
|
||||
|
||||
ins_qwery = f"""insert into public.food(name, price, gram, stock) values ('{name[i].text}', '{price[i].text}', '{gram[i].text}', '{stock[i].text}')"""
|
||||
cursor.execute(ins_qwery)
|
||||
connection.commit()
|
||||
|
||||
|
||||
|
||||
|
||||
cursor.close()
|
||||
|
||||
connection.close()
|
||||
@@ -8,7 +8,7 @@ connection = psycopg2.connect(host='localhost', dbname='dbdata', user='postgres'
|
||||
cursor = connection.cursor()
|
||||
|
||||
cr_qwery = """ create table Parser
|
||||
(id serial primary key, name varchar(100), sale varchar(30), price varchar(10), rate varchar(10), picture varchar(100))"""
|
||||
(id serial primary key, name varchar(100), price varchar(10), rate varchar(10), picture varchar(100))"""
|
||||
|
||||
#cursor.execute(cr_qwery)
|
||||
connection.commit()
|
||||
@@ -20,7 +20,6 @@ html_code = browser.page_source
|
||||
soup = BeautifulSoup(html_code, 'lxml')
|
||||
|
||||
name = soup.find_all('div', class_="product-card__title")
|
||||
sale = soup.find_all('div', class_="sc-kYrlTI ciSrDA product-card__badge")
|
||||
price = soup.find_all('div', class_="price-new")
|
||||
rate = soup.find_all('div', class_="rating-value")
|
||||
picture = soup.find_all('div', class_="product-card__image-wrapper")
|
||||
@@ -29,7 +28,7 @@ for i in range(15):
|
||||
url = picture[i].find('img').attrs['src']
|
||||
filename = f"C:\\Users\\71332\PycharmProjects\pythonProject1\\venv\Pictures\{i}.jpg"
|
||||
wget.download(url, filename)
|
||||
ins_qwery = f"""insert into public.Parser(name, sale, price, rate, picture) values ('{name[i].text}', '{sale[i].text}', '{price[i].text}', '{rate[i].text}', '{filename}')"""
|
||||
ins_qwery = f"""insert into public.Parser(name, price, rate, picture) values ('{name[i].text}', '{price[i].text}', '{rate[i].text}', '{filename}')"""
|
||||
cursor.execute(ins_qwery)
|
||||
connection.commit()
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import psycopg2
|
||||
import wget
|
||||
|
||||
from Задания.task1.Sukhanov import DZ_PARSBD
|
||||
|
||||
connection = psycopg2.connect(host='localhost', dbname='dbdata', user='postgres', password='Q1w2e3r4')
|
||||
cursor = connection.cursor()
|
||||
cr_qwery = '''create table Parser (id serial primary key, name varchar(100), price varchar(10), rate varchar(10), picture varchar(100))'''
|
||||
|
||||
try:
|
||||
cursor.execute(cr_qwery)
|
||||
connection.commit()
|
||||
except psycopg2.errors.DuplicateTable:
|
||||
print("duplicate error")
|
||||
|
||||
for j in range(15):
|
||||
url = DZ_PARSBD.picture[j].find('img').attrs['src']
|
||||
tempf = f"img\\Parser{j}.jpg"
|
||||
wget.download(url, tempf)
|
||||
try:
|
||||
insert_query = f'''INSERT into public.Parser(name, price, rate, picture) values ('{DZ_PARSBD.name[j].text}', '{DZ_PARSBD.price[j].text}', '{DZ_PARSBD.rate[j].text}', '{tempf}') '''
|
||||
cursor.execute(insert_query)
|
||||
connection.commit()
|
||||
except:
|
||||
connection.rollback()
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
Reference in New Issue
Block a user