This commit is contained in:
ada-dmitry
2023-04-11 21:01:39 +03:00
parent 7206df1883
commit 49a7b5b185
51 changed files with 168 additions and 83 deletions
+1
View File
@@ -5,6 +5,7 @@ from selenium import webdriver
from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.service import Service
import config import config
# Парсер и загрузчик в БД//Антипенко Дмитрий # Парсер и загрузчик в БД//Антипенко Дмитрий
connection = psycopg2.connect( connection = psycopg2.connect(
host=config.hostname, dbname=config.databname, user=config.username, password=config.passw) host=config.hostname, dbname=config.databname, user=config.username, password=config.passw)
+7 -4
View File
@@ -1,4 +1,7 @@
hostname = "localhost"
databname = "PythonDB"
username = "postgres" def f(a: int, b: int) -> int:
passw = "Q1w2e3r4" '''
this is an add function
'''
return a + b
Binary file not shown.
Binary file not shown.
+4
View File
@@ -0,0 +1,4 @@
hostname = "localhost"
databname = "PythonDB"
username = "postgres"
passw = "Q1w2e3r4"
+39
View File
@@ -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)
Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

+18
View File
@@ -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")
+25
View File
@@ -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()
-39
View File
@@ -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)
+9
View File
@@ -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)
+29 -4
View File
@@ -1,14 +1,39 @@
import telebot 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 = telebot.TeleBot('6285042955:AAEPprYo9K7Ta0RkDcoqO2Z4Ejdw8to1NX0')
@bot.message_handler(commands=["start"]) @bot.message_handler(commands=["start"])
def start(m, res = False): def start(m, res=False):
bot.send_message(m.chat.id, 'Бот запущен') 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"]) @bot.message_handler(content_types=["text"])
def handle_text(message): 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) bot.polling(none_stop=True, interval=0)