mirror of
https://github.com/KUlishevgeniy/c22712.git
synced 2026-09-23 23:50:21 +00:00
mutable template added
This commit is contained in:
@@ -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()
|
||||||
@@ -4,36 +4,32 @@ from selenium.webdriver.chrome.service import Service
|
|||||||
import psycopg2
|
import psycopg2
|
||||||
import wget
|
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')
|
connection = psycopg2.connect(host='localhost', dbname='dbdata', user='postgres', password='Q1w2e3r4')
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
|
create_q = '''CREATE TABLE F0ood (ID serial primary key, Name varchar(5000), Info varchar(5000), Des varchar(10000), Price varchar(600), src varchar(1000))'''
|
||||||
crtable = """ create table Notebooks
|
cursor.execute(create_q)
|
||||||
(id serial primary key, name varchar(500), description varchar(500), code varchar(200), price varchar(100),
|
|
||||||
picture varchar(500)) """
|
|
||||||
|
|
||||||
cursor.execute(crtable)
|
|
||||||
connection.commit()
|
connection.commit()
|
||||||
|
|
||||||
s = Service('C:\\Users\\Yekaterina\\Downloads\\chromedriver_win32\\chromedriver.exe')
|
for j in range(25):
|
||||||
browser = webdriver.Chrome(service=s)
|
url = Image[j].find('img').attrs['src']
|
||||||
browser.get('https://www.citilink.ru/catalog/noutbuki/')
|
tempf = f"img\\food{j}.jpg"
|
||||||
html_text = browser.page_source
|
wget.download(url, tempf)
|
||||||
soup = BeautifulSoup(html_text, 'lxml')
|
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')
|
cursor.execute("SELECT * from F0ood")
|
||||||
description = soup.find_all('div', class_='app-catalog-1o4umte eevw8x70')
|
print(cursor.fetchall())
|
||||||
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.close()
|
cursor.close()
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ browser = webdriver.Chrome(service=s)
|
|||||||
browser.get('https://www.citilink.ru/catalog/noutbuki/')
|
browser.get('https://www.citilink.ru/catalog/noutbuki/')
|
||||||
html_text = browser.page_source
|
html_text = browser.page_source
|
||||||
soup = BeautifulSoup(html_text, 'lxml')
|
soup = BeautifulSoup(html_text, 'lxml')
|
||||||
|
|
||||||
|
|
||||||
name=soup.find_all('div', class_='app-catalog-1tp0ino e1an64qs0')
|
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')
|
description=soup.find_all('div', class_='app-catalog-1o4umte eevw8x70')
|
||||||
print (description[0].text)
|
print (description[1].text)
|
||||||
|
|||||||
Reference in New Issue
Block a user