diff --git a/Python/23.03/DB1.py b/Python/23.03/DB1.py index d8e4b04..3d365ca 100644 --- a/Python/23.03/DB1.py +++ b/Python/23.03/DB1.py @@ -5,6 +5,7 @@ from selenium import webdriver from selenium.webdriver.chrome.service import Service import config + # Парсер и загрузчик в БД//Антипенко Дмитрий connection = psycopg2.connect( host=config.hostname, dbname=config.databname, user=config.username, password=config.passw) diff --git a/Python/23.03/config.py b/Python/23.03/config.py index 8a59dfc..22e1558 100644 --- a/Python/23.03/config.py +++ b/Python/23.03/config.py @@ -1,4 +1,7 @@ -hostname = "localhost" -databname = "PythonDB" -username = "postgres" -passw = "Q1w2e3r4" + + +def f(a: int, b: int) -> int: + ''' + this is an add function + ''' + return a + b diff --git a/Python/TeleBot/__pycache__/config.cpython-311.pyc b/Python/TeleBot/__pycache__/config.cpython-311.pyc new file mode 100644 index 0000000..0171f87 Binary files /dev/null and b/Python/TeleBot/__pycache__/config.cpython-311.pyc differ diff --git a/Python/TeleBot/__pycache__/parser.cpython-311.pyc b/Python/TeleBot/__pycache__/parser.cpython-311.pyc new file mode 100644 index 0000000..17b715b Binary files /dev/null and b/Python/TeleBot/__pycache__/parser.cpython-311.pyc differ diff --git a/Python/TeleBot/__pycache__/tableCreator.cpython-311.pyc b/Python/TeleBot/__pycache__/tableCreator.cpython-311.pyc new file mode 100644 index 0000000..f906620 Binary files /dev/null and b/Python/TeleBot/__pycache__/tableCreator.cpython-311.pyc differ diff --git a/Python/TeleBot/config.py b/Python/TeleBot/config.py new file mode 100644 index 0000000..8a59dfc --- /dev/null +++ b/Python/TeleBot/config.py @@ -0,0 +1,4 @@ +hostname = "localhost" +databname = "PythonDB" +username = "postgres" +passw = "Q1w2e3r4" diff --git a/Python/TeleBot/telegram.py b/Python/TeleBot/example/telegram.py similarity index 98% rename from Python/TeleBot/telegram.py rename to Python/TeleBot/example/telegram.py index 870dcaf..1981f06 100644 --- a/Python/TeleBot/telegram.py +++ b/Python/TeleBot/example/telegram.py @@ -1,36 +1,36 @@ -"""" -Чтобы создать бота, нам нужно дать ему название, адрес и получить токен — строку, которая будет -однозначно идентифицировать нашего бота для серверов Telegram. - Зайдем в Telegram под своим аккаунтом и откроем «отца всех ботов», BotFather. - -Жмем кнопку «Запустить» (или отправим /start), в ответ BotFather пришлет нам список доступных команд: -/newbot — создать нового бота; -/mybots — редактировать ваших ботов; -/setname — сменить имя бота; -/setdescription — изменить описание бота; -/setabouttext — изменить информацию о боте; -/setuserpic — изменить фото аватарки бота; -/setcommands — изменить спиcок команд бота; -/deletebot — удалить бота - -Отправим бате‑боту команду /newbot, -чтобы создать нового бота. - В ответ он попросит ввести имя будущего бота, его можно писать на русском. - После ввода имени нужно будет отправить адрес бота, причем он должен заканчиваться на слово bot. - Если адрес будет уже кем‑то занят, BotFather начнет извиняться и просить придумать что‑нибудь другое. - pip install pytelegrambotapi -""" -import telebot -# Создаем экземпляр бота -bot = telebot.TeleBot('6109683645:AAHn1BKIiiLr8FWTBrn0koyFfNN2gIpifiA') -# Функция, обрабатывающая команду /start -@bot.message_handler(commands=["start"]) -def start(m, res=False): - bot.send_message(m.chat.id, 'Я на связи. Напиши мне что-нибудь )') -# Получение сообщений от юзера -@bot.message_handler(content_types=["text"]) -def handle_text(message): - bot.send_message(message.chat.id, 'Вы написали: ' - + message.text) -# Запускаем бота +"""" +Чтобы создать бота, нам нужно дать ему название, адрес и получить токен — строку, которая будет +однозначно идентифицировать нашего бота для серверов Telegram. + Зайдем в Telegram под своим аккаунтом и откроем «отца всех ботов», BotFather. + +Жмем кнопку «Запустить» (или отправим /start), в ответ BotFather пришлет нам список доступных команд: +/newbot — создать нового бота; +/mybots — редактировать ваших ботов; +/setname — сменить имя бота; +/setdescription — изменить описание бота; +/setabouttext — изменить информацию о боте; +/setuserpic — изменить фото аватарки бота; +/setcommands — изменить спиcок команд бота; +/deletebot — удалить бота + +Отправим бате‑боту команду /newbot, +чтобы создать нового бота. + В ответ он попросит ввести имя будущего бота, его можно писать на русском. + После ввода имени нужно будет отправить адрес бота, причем он должен заканчиваться на слово bot. + Если адрес будет уже кем‑то занят, BotFather начнет извиняться и просить придумать что‑нибудь другое. + pip install pytelegrambotapi +""" +import telebot +# Создаем экземпляр бота +bot = telebot.TeleBot('6109683645:AAHn1BKIiiLr8FWTBrn0koyFfNN2gIpifiA') +# Функция, обрабатывающая команду /start +@bot.message_handler(commands=["start"]) +def start(m, res=False): + bot.send_message(m.chat.id, 'Я на связи. Напиши мне что-нибудь )') +# Получение сообщений от юзера +@bot.message_handler(content_types=["text"]) +def handle_text(message): + bot.send_message(message.chat.id, 'Вы написали: ' + + message.text) +# Запускаем бота bot.polling(none_stop=True, interval=0) \ No newline at end of file diff --git a/Python/TeleBot/example/telegram2.py b/Python/TeleBot/example/telegram2.py new file mode 100644 index 0000000..588691f --- /dev/null +++ b/Python/TeleBot/example/telegram2.py @@ -0,0 +1,39 @@ + +import telebot +import random +from telebot import types +# Загружаем список интересных фактов +# f = open('data/facts', 'r', encoding='UTF-8') +# facts = f.read().split('\n') +# f.close() +# # Загружаем список поговорок +# f = open('data/thinks.txt', 'r', encoding='UTF-8') +# thinks = f.read().split('\n') +# f.close() +# Создаем бота +bot = telebot.TeleBot('6285042955:AAEPprYo9K7Ta0RkDcoqO2Z4Ejdw8to1NX0') +# Команда start +@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) +# Получение сообщений от юзера +# (@bot.message_handler(content_types=["text"])) +# def handle_text(message): +# # Если юзер прислал 1, выдаем ему случайный факт +# if message.text.strip() == 'Факт' : +# answer = random.choice(facts) +# # Если юзер прислал 2, выдаем умную мысль +# elif message.text.strip() == 'Поговорка': +# answer = random.choice(thinks) +# # Отсылаем юзеру сообщение в его чат +# bot.send_message(message.chat.id, answer) +# Запускаем бота +bot.polling(none_stop=True, interval=0) diff --git a/Python/TeleBot/img/0 (1).jpg b/Python/TeleBot/img/0 (1).jpg new file mode 100644 index 0000000..49bd483 Binary files /dev/null and b/Python/TeleBot/img/0 (1).jpg differ diff --git a/Python/TeleBot/img/0.jpg b/Python/TeleBot/img/0.jpg new file mode 100644 index 0000000..a3605fb Binary files /dev/null and b/Python/TeleBot/img/0.jpg differ diff --git a/Python/TeleBot/img/1 (1).jpg b/Python/TeleBot/img/1 (1).jpg new file mode 100644 index 0000000..04e47ef Binary files /dev/null and b/Python/TeleBot/img/1 (1).jpg differ diff --git a/Python/TeleBot/img/1.jpg b/Python/TeleBot/img/1.jpg new file mode 100644 index 0000000..c7aea3b Binary files /dev/null and b/Python/TeleBot/img/1.jpg differ diff --git a/Python/TeleBot/img/10 (1).jpg b/Python/TeleBot/img/10 (1).jpg new file mode 100644 index 0000000..697228c Binary files /dev/null and b/Python/TeleBot/img/10 (1).jpg differ diff --git a/Python/TeleBot/img/10.jpg b/Python/TeleBot/img/10.jpg new file mode 100644 index 0000000..2dccefe Binary files /dev/null and b/Python/TeleBot/img/10.jpg differ diff --git a/Python/TeleBot/img/11 (1).jpg b/Python/TeleBot/img/11 (1).jpg new file mode 100644 index 0000000..0eeeff9 Binary files /dev/null and b/Python/TeleBot/img/11 (1).jpg differ diff --git a/Python/TeleBot/img/11.jpg b/Python/TeleBot/img/11.jpg new file mode 100644 index 0000000..7688e9c Binary files /dev/null and b/Python/TeleBot/img/11.jpg differ diff --git a/Python/TeleBot/img/12 (1).jpg b/Python/TeleBot/img/12 (1).jpg new file mode 100644 index 0000000..1f7bdb9 Binary files /dev/null and b/Python/TeleBot/img/12 (1).jpg differ diff --git a/Python/TeleBot/img/12.jpg b/Python/TeleBot/img/12.jpg new file mode 100644 index 0000000..c7c0cb4 Binary files /dev/null and b/Python/TeleBot/img/12.jpg differ diff --git a/Python/TeleBot/img/13 (1).jpg b/Python/TeleBot/img/13 (1).jpg new file mode 100644 index 0000000..46ff547 Binary files /dev/null and b/Python/TeleBot/img/13 (1).jpg differ diff --git a/Python/TeleBot/img/13.jpg b/Python/TeleBot/img/13.jpg new file mode 100644 index 0000000..4c1bf3b Binary files /dev/null and b/Python/TeleBot/img/13.jpg differ diff --git a/Python/TeleBot/img/14 (1).jpg b/Python/TeleBot/img/14 (1).jpg new file mode 100644 index 0000000..d79d495 Binary files /dev/null and b/Python/TeleBot/img/14 (1).jpg differ diff --git a/Python/TeleBot/img/14.jpg b/Python/TeleBot/img/14.jpg new file mode 100644 index 0000000..bafbe29 Binary files /dev/null and b/Python/TeleBot/img/14.jpg differ diff --git a/Python/TeleBot/img/15 (1).jpg b/Python/TeleBot/img/15 (1).jpg new file mode 100644 index 0000000..7a38c3b Binary files /dev/null and b/Python/TeleBot/img/15 (1).jpg differ diff --git a/Python/TeleBot/img/15.jpg b/Python/TeleBot/img/15.jpg new file mode 100644 index 0000000..dd5057e Binary files /dev/null and b/Python/TeleBot/img/15.jpg differ diff --git a/Python/TeleBot/img/16 (1).jpg b/Python/TeleBot/img/16 (1).jpg new file mode 100644 index 0000000..caa4c17 Binary files /dev/null and b/Python/TeleBot/img/16 (1).jpg differ diff --git a/Python/TeleBot/img/16.jpg b/Python/TeleBot/img/16.jpg new file mode 100644 index 0000000..9b8b34a Binary files /dev/null and b/Python/TeleBot/img/16.jpg differ diff --git a/Python/TeleBot/img/17 (1).jpg b/Python/TeleBot/img/17 (1).jpg new file mode 100644 index 0000000..d79d495 Binary files /dev/null and b/Python/TeleBot/img/17 (1).jpg differ diff --git a/Python/TeleBot/img/17.jpg b/Python/TeleBot/img/17.jpg new file mode 100644 index 0000000..d79d495 Binary files /dev/null and b/Python/TeleBot/img/17.jpg differ diff --git a/Python/TeleBot/img/18 (1).jpg b/Python/TeleBot/img/18 (1).jpg new file mode 100644 index 0000000..223746c Binary files /dev/null and b/Python/TeleBot/img/18 (1).jpg differ diff --git a/Python/TeleBot/img/18.jpg b/Python/TeleBot/img/18.jpg new file mode 100644 index 0000000..223746c Binary files /dev/null and b/Python/TeleBot/img/18.jpg differ diff --git a/Python/TeleBot/img/2 (1).jpg b/Python/TeleBot/img/2 (1).jpg new file mode 100644 index 0000000..c7aea3b Binary files /dev/null and b/Python/TeleBot/img/2 (1).jpg differ diff --git a/Python/TeleBot/img/2.jpg b/Python/TeleBot/img/2.jpg new file mode 100644 index 0000000..c95a406 Binary files /dev/null and b/Python/TeleBot/img/2.jpg differ diff --git a/Python/TeleBot/img/3 (1).jpg b/Python/TeleBot/img/3 (1).jpg new file mode 100644 index 0000000..083cde9 Binary files /dev/null and b/Python/TeleBot/img/3 (1).jpg differ diff --git a/Python/TeleBot/img/3.jpg b/Python/TeleBot/img/3.jpg new file mode 100644 index 0000000..0aab9e3 Binary files /dev/null and b/Python/TeleBot/img/3.jpg differ diff --git a/Python/TeleBot/img/4 (1).jpg b/Python/TeleBot/img/4 (1).jpg new file mode 100644 index 0000000..ceb59fe Binary files /dev/null and b/Python/TeleBot/img/4 (1).jpg differ diff --git a/Python/TeleBot/img/4.jpg b/Python/TeleBot/img/4.jpg new file mode 100644 index 0000000..576bce6 Binary files /dev/null and b/Python/TeleBot/img/4.jpg differ diff --git a/Python/TeleBot/img/5 (1).jpg b/Python/TeleBot/img/5 (1).jpg new file mode 100644 index 0000000..4c1bf3b Binary files /dev/null and b/Python/TeleBot/img/5 (1).jpg differ diff --git a/Python/TeleBot/img/5.jpg b/Python/TeleBot/img/5.jpg new file mode 100644 index 0000000..a7c53ab Binary files /dev/null and b/Python/TeleBot/img/5.jpg differ diff --git a/Python/TeleBot/img/6 (1).jpg b/Python/TeleBot/img/6 (1).jpg new file mode 100644 index 0000000..9417469 Binary files /dev/null and b/Python/TeleBot/img/6 (1).jpg differ diff --git a/Python/TeleBot/img/6.jpg b/Python/TeleBot/img/6.jpg new file mode 100644 index 0000000..4b3ea13 Binary files /dev/null and b/Python/TeleBot/img/6.jpg differ diff --git a/Python/TeleBot/img/7 (1).jpg b/Python/TeleBot/img/7 (1).jpg new file mode 100644 index 0000000..bafbe29 Binary files /dev/null and b/Python/TeleBot/img/7 (1).jpg differ diff --git a/Python/TeleBot/img/7.jpg b/Python/TeleBot/img/7.jpg new file mode 100644 index 0000000..2cd8120 Binary files /dev/null and b/Python/TeleBot/img/7.jpg differ diff --git a/Python/TeleBot/img/8 (1).jpg b/Python/TeleBot/img/8 (1).jpg new file mode 100644 index 0000000..0672188 Binary files /dev/null and b/Python/TeleBot/img/8 (1).jpg differ diff --git a/Python/TeleBot/img/8.jpg b/Python/TeleBot/img/8.jpg new file mode 100644 index 0000000..a22eee2 Binary files /dev/null and b/Python/TeleBot/img/8.jpg differ diff --git a/Python/TeleBot/img/9 (1).jpg b/Python/TeleBot/img/9 (1).jpg new file mode 100644 index 0000000..a7c53ab Binary files /dev/null and b/Python/TeleBot/img/9 (1).jpg differ diff --git a/Python/TeleBot/img/9.jpg b/Python/TeleBot/img/9.jpg new file mode 100644 index 0000000..ceb59fe Binary files /dev/null and b/Python/TeleBot/img/9.jpg differ diff --git a/Python/TeleBot/parser.py b/Python/TeleBot/parser.py new file mode 100644 index 0000000..b2bb715 --- /dev/null +++ b/Python/TeleBot/parser.py @@ -0,0 +1,18 @@ +from bs4 import BeautifulSoup +from selenium import webdriver +from selenium.webdriver.chrome.service import Service + +driver = Service('D:\\teach\Prog\chromedriver.exe') +browser = webdriver.Chrome(service=driver) +browser.get( + 'https://amwine.ru/catalog/igristoe_vino_i_shampanskoe/igristoe_vino/') +html_code = browser.page_source +b_soup = BeautifulSoup(html_code, 'lxml') +name = b_soup.find_all( + 'a', class_="catalog-list-item__title js-product-detail-link") +price = b_soup.find_all('span', class_="middle_price") +priceDis = b_soup.find_all('span', class_="baseoldprice") +mark = b_soup.find_all('span', class_="product-rating__rating") +pictures = b_soup.find_all('div', class_="catalog-list-item__img-wrapper") + + diff --git a/Python/TeleBot/tableCreator.py b/Python/TeleBot/tableCreator.py new file mode 100644 index 0000000..39c28e2 --- /dev/null +++ b/Python/TeleBot/tableCreator.py @@ -0,0 +1,25 @@ +import psycopg2 +import wget +import parser +import config + +connection = psycopg2.connect(host=config.hostname, dbname=config.databname, user=config.username, password=config.passw) +cursor = connection.cursor() + +creat_qwery = """ create table Parser + (id serial primary key, page_name varchar(100), price varchar(10), priceDis varchar(30), mark varchar(10), scr varchar(100))""" + +cursor.execute(creat_qwery) +connection.commit() +for i in range(15): + print(i) + url = 'https://amwine.ru' + parser.pictures[i].find('a').find('img').attrs['data-src'] + filename = f"Python\\TeleBot\img\{i}.jpg" + wget.download(url, filename) + ins_qwery = f"""insert into public.Parser(page_name, price, priceDis, mark, scr) values ('{parser.name[i].text}', '{parser.price[i].text}', '{parser.priceDis[i].text}', '{parser.mark[i].text}', '{filename}')""" + cursor.execute(ins_qwery) + connection.commit() + +cursor.close() + +connection.close() \ No newline at end of file diff --git a/Python/TeleBot/telegram2.py b/Python/TeleBot/telegram2.py deleted file mode 100644 index 1c14c12..0000000 --- a/Python/TeleBot/telegram2.py +++ /dev/null @@ -1,39 +0,0 @@ - -import telebot -import random -from telebot import types -# Загружаем список интересных фактов -f = open('data/facts', 'r', encoding='UTF-8') -facts = f.read().split('\n') -f.close() -# Загружаем список поговорок -f = open('data/thinks.txt', 'r', encoding='UTF-8') -thinks = f.read().split('\n') -f.close() -# Создаем бота -bot = telebot.TeleBot('6109683645:AAHn1BKIiiLr8FWTBrn0koyFfNN2gIpifiA') -# Команда start -@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) -# Получение сообщений от юзера -@bot.message_handler(content_types=["text"]) -def handle_text(message): - # Если юзер прислал 1, выдаем ему случайный факт - if message.text.strip() == 'Факт' : - answer = random.choice(facts) - # Если юзер прислал 2, выдаем умную мысль - elif message.text.strip() == 'Поговорка': - answer = random.choice(thinks) - # Отсылаем юзеру сообщение в его чат - bot.send_message(message.chat.id, answer) -# Запускаем бота -bot.polling(none_stop=True, interval=0) diff --git a/Python/TeleBot/test.py b/Python/TeleBot/test.py new file mode 100644 index 0000000..8d41f23 --- /dev/null +++ b/Python/TeleBot/test.py @@ -0,0 +1,9 @@ +def f(): + a = [1,2,3] + b = [3,4,5] + c = ["1", "2", "3"] + return a,b,c + +a,b,c = f() + +print(a, b, c) \ No newline at end of file diff --git a/Python/TeleBot/tgBot.py b/Python/TeleBot/tgBot.py index 6f48832..4bab651 100644 --- a/Python/TeleBot/tgBot.py +++ b/Python/TeleBot/tgBot.py @@ -1,14 +1,39 @@ import telebot +import psycopg2 +import config +from telebot import types +import random +import tableCreator #включать лишь тогда, когда таблицы ещё нет + +connection = psycopg2.connect(host=config.hostname, dbname=config.databname, user=config.username, password=config.passw) +cursor = connection.cursor() + +sel_query = """SELECT * FROM public.parser""" +cursor.execute(sel_query) +array = list(cursor.fetchall()) bot = telebot.TeleBot('6285042955:AAEPprYo9K7Ta0RkDcoqO2Z4Ejdw8to1NX0') @bot.message_handler(commands=["start"]) -def start(m, res = False): - bot.send_message(m.chat.id, 'Бот запущен') +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 "Повтори!" - для повторения сообщений.', reply_markup=markup) @bot.message_handler(content_types=["text"]) - def handle_text(message): - bot.send_message(message.chat.id, 'Ввод: '+message.text) + if(message.text.strip() == 'Рандомное вино!'): + i = random.choice(array) + ans = f'Название: {i[1]}\nЦена: {i[2]}\nЦена без скидки: {i[3]}\nОценка: {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) \ No newline at end of file + +bot.polling(none_stop=True, interval=0) + +