From 1af420a038aff74da8886004250200d8011ce153 Mon Sep 17 00:00:00 2001 From: Lady Di <93448337+dialuna@users.noreply.github.com> Date: Wed, 28 Jun 2023 21:11:13 +0300 Subject: [PATCH] =?UTF-8?q?Delete=20=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F/task1/Gasanova=20directory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Задания/task1/Gasanova/bot_database.py | 67 ------------------- Задания/task1/Gasanova/parsing.py | 30 --------- Задания/task1/Gasanova/tbot.py | 90 -------------------------- 3 files changed, 187 deletions(-) delete mode 100644 Задания/task1/Gasanova/bot_database.py delete mode 100644 Задания/task1/Gasanova/parsing.py delete mode 100644 Задания/task1/Gasanova/tbot.py diff --git a/Задания/task1/Gasanova/bot_database.py b/Задания/task1/Gasanova/bot_database.py deleted file mode 100644 index 1c3d867..0000000 --- a/Задания/task1/Gasanova/bot_database.py +++ /dev/null @@ -1,67 +0,0 @@ -import telebot -import psycopg2 -from telebot import types -import random - -connection = psycopg2.connect(host='localhost', dbname='work', user='dialuna', password='Timka07') # да-да :D -cursor = connection.cursor() - -try: - sel_query = """SELECT * FROM bot""" - cursor.execute(sel_query) -except psycopg2.errors.UndefinedTable: - connection.rollback() - import problems - sel_query = """SELECT * FROM bot""" - cursor.execute(sel_query) - -array = list(cursor.fetchall()) - - -bot = telebot.TeleBot('secret') - -@bot.message_handler(commands=['start']) -def start(message): - sti = open('st.webp', 'rb') - bot.send_sticker(message.chat.id, sti) - bot.send_message(message.chat.id, "ЙОУ, {0.first_name}!\nЯ твой помощник в мире скейтбординга😎".format(message.from_user, bot.get_me())) - - markup = types.ReplyKeyboardMarkup(resize_keyboard=True) #создание кнопок - btn1 = types.KeyboardButton("Лучший скейтборд этого сезона") - btn2 = types.KeyboardButton("Предложение дня") - btn3 = types.KeyboardButton("Выбор редакции нашей компании") - markup.add(btn1, btn2, btn3) - bot.send_message(message.chat.id, - 'Лучший скейтборд этого сезона - это именно то, что тебе нужно, если хочешь быть самым крутым.\nПредложение дня - то, что актуально на сегодняшний день.\nВыбор редакции - просто доверься выбору наших сотрудников и тебе понравится :)\n', - reply_markup=markup) - - -@bot.message_handler(content_types=['text']) -def handle_text(message): - if (message.text.strip() == "Лучший скейтборд этого сезона"): - i = random.choice(array) - inf = f'Название: {i[2]}\nЦена: {i[3]}\n' - bot.send_message(message.chat.id, inf) - bot.send_photo(message.chat.id, open(i[4], 'rb')) - cat = open('kotik.webm', 'rb') - bot.send_video(message.chat.id, cat) - elif (message.text.strip() == "Предложение дня"): - i = random.choice(array) - inf = f'Название: {i[2]}\nЦена: {i[3]}\n' - bot.send_message(message.chat.id, inf) - bot.send_photo(message.chat.id, open(i[4], 'rb')) - cat = open('kotik.webm', 'rb') - bot.send_video(message.chat.id, cat) - elif (message.text.strip() == "Выбор редакции нашей компании"): - i = random.choice(array) - inf = f'Название: {i[2]}\nЦена: {i[3]}\n' - bot.send_message(message.chat.id, inf) - bot.send_photo(message.chat.id, open(i[4], 'rb')) - cat = open('kotik.webm', 'rb') - bot.send_video(message.chat.id, cat) - else: - bot.send_message(message.chat.id, "Наш бот поможет подобрать вам или близким скейтборд мечты. Скорее пробуйте! ") - - - -bot.polling(none_stop=True, interval=0) diff --git a/Задания/task1/Gasanova/parsing.py b/Задания/task1/Gasanova/parsing.py deleted file mode 100644 index ffecd72..0000000 --- a/Задания/task1/Gasanova/parsing.py +++ /dev/null @@ -1,30 +0,0 @@ -# парсер к полусему 8 неделя -from bs4 import BeautifulSoup -from selenium import webdriver -from selenium.webdriver.chrome.service import Service -from wget import download -import psycopg2 as psyc - -# s = Service("chromedriver") на Ubuntu можно не указывать путь до драйвера если что :) -URL = "https://proskateshop.ru/skejtbordy/?utm_source=yandex&utm_medium=cpc&utm_campaign=cn%7Cskeyty_gz-1%7Ccid%7C51517250%7Csearch&utm_content=gid%7C4180310153%7Caid%7C8980588780%7C20506942844_20506942844%7Cmain&utm_term=%D0%9F%D0%B5%D0%BD%D0%BD%D0%B8%20%D0%B1%D0%BE%D1%80%D0%B4%20%D0%BA%D1%83%D0%BF%D0%B8%D1%82%D1%8C&etext=2202.N39xvihj0F0Od_d4etv_6nh36sdlRP-T26wHLuCJfjo_JZtVI5O7HY5f8FOJnzuLZXB6eWZoZnp2dG1laHBlcA.aceac50a24e4832d82874cd59ca1f9a315d9b351&_openstat=ZGlyZWN0LnlhbmRleC5ydTs1MTUxNzI1MDs4OTgwNTg4NzgwO3lhbmRleC5ydTpndWFyYW50ZWU&yclid=1445113833197462400" -brow = webdriver.Chrome() -brow.get(URL) - -html = brow.page_source - -soup = BeautifulSoup(html, "lxml") - -penny = soup.find_all(attrs={"class": "product-layout product-grid col-lg-4 col-md-4 col-sm-6 col-xs-6"}) - -with psyc.connect(host = "localhost", dbname="work", user="dialuna", password = "Timka07") as conn: - with conn.cursor() as cursor: - for i, product in enumerate(penny[1:]): - image_link = product.find("img").attrs.get("src") - image_name = product.find("img").attrs.get("alt") - price = product.find("p", attrs={"class": "price"}).text.strip() - download( product.find("img").attrs.get("src"), f"images/{i}.jpg") - - cursor.execute(f"""insert into bot(link, name, price, file) - values ('{image_link}', '{image_name}', '{price}', 'images/{i}.jpg')""") - - conn.commit() diff --git a/Задания/task1/Gasanova/tbot.py b/Задания/task1/Gasanova/tbot.py deleted file mode 100644 index 8b894d3..0000000 --- a/Задания/task1/Gasanova/tbot.py +++ /dev/null @@ -1,90 +0,0 @@ -import telebot -import psycopg2 -from telebot import types -import random - -connection = psycopg2.connect(host='localhost', dbname='work', user='dialuna', password='Timka07') # да-да :D -cursor = connection.cursor() - -try: - sel_query = """SELECT * FROM bot""" - cursor.execute(sel_query) -except psycopg2.errors.UndefinedTable: - connection.rollback() - import problems - sel_query = """SELECT * FROM bot""" - cursor.execute(sel_query) - -array = list(cursor.fetchall()) - -def select(ID): - s_query = f'''SELECT * FROM bot where ID = {ID}''' - cursor.execute(s_query) - return cursor.fetchone() - - - - -bot = telebot.TeleBot('secret') - -@bot.message_handler(commands=['start']) -def start(message): - sti = open('st.webp', 'rb') - bot.send_sticker(message.chat.id, sti) - bot.send_message(message.chat.id, "ЙОУ, {0.first_name}!\nЯ твой помощник в мире скейтбординга😎".format(message.from_user, bot.get_me())) - - markup = types.ReplyKeyboardMarkup(resize_keyboard=True) #создание кнопок - btn1 = types.KeyboardButton("Лучший скейтборд этого сезона") - btn2 = types.KeyboardButton("Предложение дня") - btn3 = types.KeyboardButton("Выбор скейта по ID") - markup.add(btn1, btn2, btn3) - bot.send_message(message.chat.id, - 'Лучший скейтборд этого сезона - это именно то, что тебе нужно, если хочешь быть самым крутым.\nПредложение дня - то, что актуально на сегодняшний день.\nВыбор скейта по ID - просто доверься выбору наших сотрудников и тебе понравится :)\n', - reply_markup=markup) - - -@bot.message_handler(content_types=['text']) -def handle_text(message): - if (message.text.strip() == "Лучший скейтборд этого сезона"): - i = random.choice(array) - inf = f'Название: {i[2]}\nЦена: {i[3]}\n' - bot.send_message(message.chat.id, inf) - bot.send_photo(message.chat.id, open(i[4], 'rb')) - cat = open('kotik.webm', 'rb') - bot.send_video(message.chat.id, cat) - elif (message.text.strip() == "Предложение дня"): - i = random.choice(array) - inf = f'Название: {i[2]}\nЦена: {i[3]}\n' - bot.send_message(message.chat.id, inf) - bot.send_photo(message.chat.id, open(i[4], 'rb')) - cat = open('kotik.webm', 'rb') - bot.send_video(message.chat.id, cat) - elif (message.text.strip() == "Выбор скейта по ID"): - sent = bot.send_message(message.chat.id, - f'Введите идентификатор(ID, целое число) от 1 до 13, чтобы получить информацию о конкретном предложении: ') - bot.register_next_step_handler(sent, ret_id) - else: - bot.send_message(message.chat.id, "Наш бот поможет подобрать вам или близким скейтборд мечты. Скорее пробуйте! ") - -def ret_id(message): - try: - now_id = (message.text) - now_id = int(float(now_id)) - z = list(select(now_id)) - a2 = f'Название: {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() -connection.close() - - -