reboot rep
@@ -0,0 +1,47 @@
|
||||
import psycopg2
|
||||
import wget
|
||||
from bs4 import BeautifulSoup
|
||||
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)
|
||||
|
||||
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()
|
||||
|
||||
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")
|
||||
|
||||
for i in range(15):
|
||||
url = 'https://amwine.ru' + \
|
||||
pictures[i].find('a').find('img').attrs['data-src']
|
||||
filename = f"Python\\23.03\img\{i}.jpg"
|
||||
print(filename)
|
||||
wget.download(url, filename)
|
||||
ins_qwery = f"""insert into public.Parser(page_name, price, priceDis, mark, scr) values ('{name[i].text}', '{price[i].text}', '{priceDis[i].text}', '{mark[i].text}', '{filename}')"""
|
||||
cursor.execute(ins_qwery)
|
||||
connection.commit()
|
||||
|
||||
|
||||
cursor.close()
|
||||
|
||||
connection.close()
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
|
||||
def f(a: int, b: int) -> int:
|
||||
'''
|
||||
this is an add function
|
||||
'''
|
||||
return a + b
|
||||
|
After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 118 KiB |
|
After Width: | Height: | Size: 118 KiB |
|
After Width: | Height: | Size: 84 KiB |
|
After Width: | Height: | Size: 84 KiB |
|
After Width: | Height: | Size: 95 KiB |
|
After Width: | Height: | Size: 95 KiB |
|
After Width: | Height: | Size: 95 KiB |
|
After Width: | Height: | Size: 95 KiB |
|
After Width: | Height: | Size: 86 KiB |
|
After Width: | Height: | Size: 86 KiB |
|
After Width: | Height: | Size: 97 KiB |
|
After Width: | Height: | Size: 97 KiB |
|
After Width: | Height: | Size: 78 KiB |
|
After Width: | Height: | Size: 78 KiB |
|
After Width: | Height: | Size: 92 KiB |
|
After Width: | Height: | Size: 92 KiB |
|
After Width: | Height: | Size: 80 KiB |
|
After Width: | Height: | Size: 80 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 96 KiB |
|
After Width: | Height: | Size: 96 KiB |
|
After Width: | Height: | Size: 79 KiB |
|
After Width: | Height: | Size: 79 KiB |
|
After Width: | Height: | Size: 120 KiB |
|
After Width: | Height: | Size: 120 KiB |
|
After Width: | Height: | Size: 126 KiB |
|
After Width: | Height: | Size: 126 KiB |
@@ -0,0 +1,30 @@
|
||||
'''
|
||||
print("Введите размер массива: ")
|
||||
n = int(input())
|
||||
a = [int(input()) for i in range(n)]
|
||||
'''
|
||||
a = [4,3,2,5,1]
|
||||
b = a.copy()
|
||||
def sortSelect(arr):
|
||||
for i in range(len(arr)-1):
|
||||
ind = i
|
||||
for j in range(i+1, len(arr)):
|
||||
if(arr[ind]>arr[j]):
|
||||
ind = j
|
||||
arr[i], arr[ind] = arr[ind], arr[i]
|
||||
return arr
|
||||
|
||||
|
||||
def sortInsert(arr):
|
||||
for i in range(len(arr)):
|
||||
j = i-1
|
||||
x = arr[i]
|
||||
while((arr[j]>x)and(j>=0)):
|
||||
arr[j+1] = arr[j]
|
||||
j -= 1
|
||||
arr[j+1] = x
|
||||
return arr
|
||||
#meow
|
||||
|
||||
|
||||
print(sortSelect(a), sortInsert(b))
|
||||
@@ -0,0 +1,13 @@
|
||||
def sel(cursor, tabl):
|
||||
query = f"""SELECT * FROM public.{tabl}"""
|
||||
cursor.execute(query)
|
||||
array = list(cursor.fetchall())
|
||||
return array
|
||||
|
||||
|
||||
def upd(conn, cursor, tabl):
|
||||
import parser
|
||||
for i in range(15):
|
||||
up_query = f"""UPDATE {tabl} SET page_name = '{parser.name[i].text}', price = '{parser.price[i].text}', priceDis = '{parser.priceDis[i].text}', mark = '{parser.mark[i].text}' WHERE id = {i+1}"""
|
||||
cursor.execute(up_query)
|
||||
conn.commit()
|
||||
@@ -0,0 +1,5 @@
|
||||
hostname = "localhost"
|
||||
databname = "postgres"
|
||||
username = "ada"
|
||||
passw = "?Ri588856"
|
||||
api = "6285042955:AAEPprYo9K7Ta0RkDcoqO2Z4Ejdw8to1NX0"
|
||||
@@ -0,0 +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)
|
||||
# Запускаем бота
|
||||
bot.polling(none_stop=True, interval=0)
|
||||
@@ -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: 104 KiB |
|
After Width: | Height: | Size: 97 KiB |
|
After Width: | Height: | Size: 82 KiB |
|
After Width: | Height: | Size: 92 KiB |
|
After Width: | Height: | Size: 97 KiB |
|
After Width: | Height: | Size: 224 KiB |
|
After Width: | Height: | Size: 1.2 MiB |
|
After Width: | Height: | Size: 1.3 MiB |
|
After Width: | Height: | Size: 86 KiB |
|
After Width: | Height: | Size: 64 KiB |
|
After Width: | Height: | Size: 98 KiB |
|
After Width: | Height: | Size: 118 KiB |
|
After Width: | Height: | Size: 206 KiB |
|
After Width: | Height: | Size: 126 KiB |
|
After Width: | Height: | Size: 86 KiB |
|
After Width: | Height: | Size: 94 KiB |
|
After Width: | Height: | Size: 97 KiB |
|
After Width: | Height: | Size: 101 KiB |
|
After Width: | Height: | Size: 32 KiB |
@@ -0,0 +1,16 @@
|
||||
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,36 @@
|
||||
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))"""
|
||||
|
||||
try:
|
||||
cursor.execute(creat_qwery)
|
||||
connection.commit()
|
||||
except psycopg2.errors.DuplicateTable:
|
||||
print("")
|
||||
|
||||
|
||||
for i in range(20):
|
||||
url = 'https://amwine.ru' + \
|
||||
parser.pictures[i].find('a').find('img').attrs['data-src']
|
||||
filename = f"Python/TeleBot/image/{i}.jpg"
|
||||
try:
|
||||
img = open(filename)
|
||||
except IOError as e:
|
||||
wget.download(url, filename)
|
||||
try:
|
||||
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()
|
||||
except:
|
||||
connection.rollback()
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
@@ -0,0 +1,14 @@
|
||||
import psycopg2
|
||||
import wget
|
||||
import config
|
||||
|
||||
|
||||
connection = psycopg2.connect(host=config.hostname, dbname=config.databname, user=config.username, password=config.passw)
|
||||
cursor = connection.cursor()
|
||||
|
||||
def sel(a):
|
||||
s_query = f"""SELECT * FROM public.parser WHERE id = {a}"""
|
||||
print(cursor.execute(s_query))
|
||||
return cursor.fetchone()
|
||||
|
||||
print(sel(10))
|
||||
@@ -0,0 +1,53 @@
|
||||
import telebot
|
||||
import psycopg2
|
||||
import config
|
||||
from telebot import types
|
||||
import random
|
||||
import FuncForBot
|
||||
|
||||
connection = psycopg2.connect(
|
||||
host=config.hostname, dbname=config.databname, user=config.username, password=config.passw)
|
||||
cursor = connection.cursor()
|
||||
try:
|
||||
array = FuncForBot.sel(cursor, 'parser')
|
||||
except psycopg2.errors.UndefinedTable:
|
||||
connection.rollback()
|
||||
import tableCreator
|
||||
array = FuncForBot.sel(cursor, 'parser')
|
||||
finally:
|
||||
FuncForBot.upd(connection, cursor, 'parser')
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
bot = telebot.TeleBot(config.api)
|
||||
|
||||
|
||||
@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 Введите число(1-20) для вывода определенной позиции\n "Повтори!" - для повторения сообщений.', reply_markup=markup)
|
||||
|
||||
|
||||
@bot.message_handler(content_types=["text"])
|
||||
def handle_text(message):
|
||||
m = message.text.strip()
|
||||
if (m == 'Рандомное вино!'):
|
||||
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 (m.isnumeric() == True):
|
||||
i = array[int(m)]
|
||||
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 (m == 'Повтори!'):
|
||||
bot.send_message(message.chat.id, 'Ввод: ' + message.text)
|
||||
|
||||
|
||||
bot.polling(none_stop=True, interval=0)
|
||||
@@ -0,0 +1,43 @@
|
||||
from bs4 import BeautifulSoup
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
import psycopg2
|
||||
import wget
|
||||
|
||||
# connection = psycopg2.connect(host='localhost', dbname='dbdata', user='postgres', password='Q1w2e3r4')
|
||||
# cursor = connection.cursor()
|
||||
|
||||
s = Service('D:\Games\data\chromedriver.exe')
|
||||
browser = webdriver.Chrome(service=s)
|
||||
browser.get('https://www.volkswagen.ru/polo/')
|
||||
html_text = browser.page_source
|
||||
soup = BeautifulSoup(html_text, 'lxml')
|
||||
|
||||
# creat_table = """ create table Cars_volks
|
||||
# (id serial primary key, car_name varchar(20),
|
||||
# price varchar(15), adress varchar(40),
|
||||
# scr varchar(100)) """
|
||||
#cursor.execute(creat_table)
|
||||
# connection.commit()
|
||||
|
||||
car_names = soup.find_all('div', class_='avn001-2_name')
|
||||
prices = soup.find_all('div', class_='avn001-2_price-container')
|
||||
adresses = soup.find_all('div', class_='avn001-2_dealer-link__text')
|
||||
pictures = soup.find_all('div', class_='avn001-2_image image__container')
|
||||
|
||||
#for car_name, adress, price in zip(car_names, adresses, prices):
|
||||
# print(f"Название машины:{car_name.text} | Адрес диллера: {adress.text} | Цена: {price.text} рублей")
|
||||
|
||||
for i in range(4):
|
||||
url = pictures[i].find('img').attrs['src']
|
||||
filename = f"Programming\\other\\img\\img{i}.jpg"
|
||||
print(filename)
|
||||
wget.download(url, filename)
|
||||
|
||||
# insert_qwery = f"""INSERT INTO public.Cars_volks(car_name, price, adress, scr)
|
||||
# VALUES ('{car_names[i].text}', '{prices[i].text}', '{adresses[i].text}', '{filename}')""";
|
||||
# cursor.execute(insert_qwery)
|
||||
# connection.commit()
|
||||
|
||||
# cursor.close()
|
||||
# connection.close()
|
||||
@@ -0,0 +1,33 @@
|
||||
from bs4 import BeautifulSoup
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
import psycopg2
|
||||
import wget
|
||||
|
||||
browser = webdriver.Chrome(service=Service('C:\Desktop\exe\chromedriver.exe'))
|
||||
browser.get('https://flawery.ru/moscow/bouquets/event-yanvary25/')
|
||||
soup = BeautifulSoup(browser.page_source, "lxml")
|
||||
Name = soup.find_all(attrs={"class": "catalog_title"})
|
||||
Price = soup.find_all(attrs={"class": "catalog_price_now"})
|
||||
Delivery_Time = soup.find_all(attrs={"class": "catalog_express"})
|
||||
Delivery_Price = soup.find_all(attrs={"class": "catalog_delivery"})
|
||||
Image = soup.find_all('div', class_="catalog_item catalog_item_popup")
|
||||
|
||||
connection = psycopg2.connect(host='localhost', dbname='FHWDB', user='postgres', password='Q1w2e3r4')
|
||||
cursor = connection.cursor()
|
||||
create_q = '''CREATE TABLE Parse
|
||||
(ID serial primary key, Name varchar(100), Price varchar(9), Delivery_Time varchar(25), Delivery_Price varchar(20), src varchar(110))'''
|
||||
cursor.execute(create_q)
|
||||
connection.commit()
|
||||
|
||||
for j in range(10):
|
||||
url = 'https://flawery.ru'+Image[j].find('a').find('img').attrs['src']
|
||||
print(url)
|
||||
tempf = f'C:\\Users\\user\\Desktop\\FHWDB{j}.jpg'
|
||||
wget.download(url, tempf)
|
||||
insert_query = f'''INSERT into public.Parse(Name, Price, Delivery_Time, Delivery_Price, scr) values ('{Name[j].text}', '{Price[j].text}', '{Delivery_Time[j].text}', '{Delivery_Price[j].text}', '{tempf}') '''
|
||||
cursor.execute(insert_query)
|
||||
connection.commit()
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 23 KiB |
@@ -0,0 +1,40 @@
|
||||
|
||||
#Вариант с пары
|
||||
'''
|
||||
from bs4 import BeautifulSoup
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
import time
|
||||
|
||||
S = Service('D:\teach\Prog\chromedriver.exe') #Открыли драйвер для хрома
|
||||
browser = webdriver.Chrome(service=S) #Инициировали в отдельную переменную
|
||||
browser.get('https://www.kinopoisk.ru/lists/movies/top250/')
|
||||
html_text = browser.page_source
|
||||
time.sleep(20)
|
||||
soup = BeautifulSoup(html_text, 'lxml')
|
||||
films = soup.find_all('div', class_='base-movie-main-info_mainInfo__ZL_u3')
|
||||
|
||||
print(soup)
|
||||
print(films)
|
||||
|
||||
for film in films:
|
||||
print(film.text)
|
||||
'''
|
||||
#Домашка
|
||||
|
||||
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://hmbrussia.ru/regional-office/')
|
||||
html_code = browser.page_source
|
||||
b_soup = BeautifulSoup(html_code, 'lxml')
|
||||
name = b_soup.find_all('div', class_="ps-xl-3 ms-xl-3")
|
||||
|
||||
print(b_soup)
|
||||
print(name)
|
||||
|
||||
for i in name:
|
||||
print(i.text)
|
||||
@@ -0,0 +1,10 @@
|
||||
# Исключения
|
||||
|
||||
try: # Указываем "опасное место"
|
||||
2/0
|
||||
except: # Проверка на все ошибки
|
||||
print('Абшибка')
|
||||
else: # Вывод только если нет ошибок
|
||||
print('Абшибак нет')
|
||||
finally: # Вывод всегда
|
||||
print('А пуфик')
|
||||