tgbot1.0
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
hostname = "localhost"
|
||||
databname = "PythonDB"
|
||||
username = "postgres"
|
||||
passw = "Q1w2e3r4"
|
||||
@@ -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)
|
||||
|
After Width: | Height: | Size: 84 KiB |
|
After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 104 KiB |
|
After Width: | Height: | Size: 118 KiB |
|
After Width: | Height: | Size: 97 KiB |
|
After Width: | Height: | Size: 84 KiB |
|
After Width: | Height: | Size: 82 KiB |
|
After Width: | Height: | Size: 95 KiB |
|
After Width: | Height: | Size: 93 KiB |
|
After Width: | Height: | Size: 95 KiB |
|
After Width: | Height: | Size: 92 KiB |
|
After Width: | Height: | Size: 86 KiB |
|
After Width: | Height: | Size: 97 KiB |
|
After Width: | Height: | Size: 97 KiB |
|
After Width: | Height: | Size: 224 KiB |
|
After Width: | Height: | Size: 126 KiB |
|
After Width: | Height: | Size: 1.2 MiB |
|
After Width: | Height: | Size: 81 KiB |
|
After Width: | Height: | Size: 97 KiB |
|
After Width: | Height: | Size: 97 KiB |
|
After Width: | Height: | Size: 97 KiB |
|
After Width: | Height: | Size: 97 KiB |
|
After Width: | Height: | Size: 118 KiB |
|
After Width: | Height: | Size: 78 KiB |
|
After Width: | Height: | Size: 206 KiB |
|
After Width: | Height: | Size: 92 KiB |
|
After Width: | Height: | Size: 126 KiB |
|
After Width: | Height: | Size: 80 KiB |
|
After Width: | Height: | Size: 86 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 94 KiB |
|
After Width: | Height: | Size: 96 KiB |
|
After Width: | Height: | Size: 97 KiB |
|
After Width: | Height: | Size: 79 KiB |
|
After Width: | Height: | Size: 101 KiB |
|
After Width: | Height: | Size: 120 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 126 KiB |
@@ -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")
|
||||
|
||||
|
||||
@@ -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()
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||