try_except_for_tgBot
@@ -2,3 +2,4 @@ hostname = "localhost"
|
|||||||
databname = "PythonDB"
|
databname = "PythonDB"
|
||||||
username = "postgres"
|
username = "postgres"
|
||||||
passw = "Q1w2e3r4"
|
passw = "Q1w2e3r4"
|
||||||
|
api = "6285042955:AAEPprYo9K7Ta0RkDcoqO2Z4Ejdw8to1NX0"
|
||||||
|
Before Width: | Height: | Size: 84 KiB |
|
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 84 KiB |
|
Before Width: | Height: | Size: 104 KiB |
|
Before Width: | Height: | Size: 118 KiB After Width: | Height: | Size: 104 KiB |
|
Before Width: | Height: | Size: 97 KiB |
|
Before Width: | Height: | Size: 84 KiB After Width: | Height: | Size: 97 KiB |
|
Before Width: | Height: | Size: 82 KiB |
|
Before Width: | Height: | Size: 95 KiB After Width: | Height: | Size: 82 KiB |
|
Before Width: | Height: | Size: 93 KiB |
|
Before Width: | Height: | Size: 95 KiB After Width: | Height: | Size: 93 KiB |
|
Before Width: | Height: | Size: 92 KiB |
|
Before Width: | Height: | Size: 86 KiB After Width: | Height: | Size: 92 KiB |
|
Before Width: | Height: | Size: 97 KiB |
|
Before Width: | Height: | Size: 97 KiB After Width: | Height: | Size: 97 KiB |
|
Before Width: | Height: | Size: 224 KiB |
|
Before Width: | Height: | Size: 126 KiB |
|
Before Width: | Height: | Size: 1.2 MiB |
|
Before Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 97 KiB |
|
Before Width: | Height: | Size: 97 KiB |
|
Before Width: | Height: | Size: 97 KiB |
|
Before Width: | Height: | Size: 97 KiB |
|
Before Width: | Height: | Size: 118 KiB |
|
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 118 KiB |
|
Before Width: | Height: | Size: 206 KiB |
|
Before Width: | Height: | Size: 92 KiB After Width: | Height: | Size: 206 KiB |
|
Before Width: | Height: | Size: 126 KiB |
|
Before Width: | Height: | Size: 80 KiB After Width: | Height: | Size: 126 KiB |
|
Before Width: | Height: | Size: 86 KiB |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 86 KiB |
|
Before Width: | Height: | Size: 94 KiB |
|
Before Width: | Height: | Size: 96 KiB After Width: | Height: | Size: 94 KiB |
|
Before Width: | Height: | Size: 97 KiB |
|
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 97 KiB |
|
Before Width: | Height: | Size: 101 KiB |
|
Before Width: | Height: | Size: 120 KiB After Width: | Height: | Size: 101 KiB |
|
Before Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 126 KiB After Width: | Height: | Size: 32 KiB |
@@ -3,22 +3,31 @@ import wget
|
|||||||
import parser
|
import parser
|
||||||
import config
|
import config
|
||||||
|
|
||||||
|
|
||||||
connection = psycopg2.connect(host=config.hostname, dbname=config.databname, user=config.username, password=config.passw)
|
connection = psycopg2.connect(host=config.hostname, dbname=config.databname, user=config.username, password=config.passw)
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
|
|
||||||
creat_qwery = """ create table Parser
|
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))"""
|
(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()
|
||||||
|
try:
|
||||||
|
cursor.execute(creat_qwery)
|
||||||
|
connection.commit()
|
||||||
|
except psycopg2.errors.DuplicateTable:
|
||||||
|
print("s")
|
||||||
|
|
||||||
|
|
||||||
cursor.execute(creat_qwery)
|
|
||||||
connection.commit()
|
|
||||||
for i in range(15):
|
for i in range(15):
|
||||||
print(i)
|
print(i)
|
||||||
url = 'https://amwine.ru' + parser.pictures[i].find('a').find('img').attrs['data-src']
|
url = 'https://amwine.ru' + parser.pictures[i].find('a').find('img').attrs['data-src']
|
||||||
filename = f"Python\\TeleBot\img\{i}.jpg"
|
filename = f"Python\\TeleBot\img\{i}.jpg"
|
||||||
wget.download(url, filename)
|
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}')"""
|
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)
|
cursor.execute(ins_qwery)
|
||||||
connection.commit()
|
connection.commit()
|
||||||
|
except:
|
||||||
|
connection.rollback()
|
||||||
|
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
|
|||||||
@@ -3,16 +3,21 @@ import psycopg2
|
|||||||
import config
|
import config
|
||||||
from telebot import types
|
from telebot import types
|
||||||
import random
|
import random
|
||||||
import tableCreator #включать лишь тогда, когда таблицы ещё нет
|
|
||||||
|
|
||||||
connection = psycopg2.connect(host=config.hostname, dbname=config.databname, user=config.username, password=config.passw)
|
connection = psycopg2.connect(host=config.hostname, dbname=config.databname, user=config.username, password=config.passw)
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
|
try:
|
||||||
|
sel_query = """SELECT * FROM public.parser"""
|
||||||
|
cursor.execute(sel_query)
|
||||||
|
except psycopg2.errors.UndefinedTable:
|
||||||
|
connection.rollback()
|
||||||
|
import tableCreator
|
||||||
|
sel_query = """SELECT * FROM public.parser"""
|
||||||
|
cursor.execute(sel_query)
|
||||||
|
|
||||||
sel_query = """SELECT * FROM public.parser"""
|
|
||||||
cursor.execute(sel_query)
|
|
||||||
array = list(cursor.fetchall())
|
array = list(cursor.fetchall())
|
||||||
|
|
||||||
bot = telebot.TeleBot('6285042955:AAEPprYo9K7Ta0RkDcoqO2Z4Ejdw8to1NX0')
|
bot = telebot.TeleBot(config.api)
|
||||||
@bot.message_handler(commands=["start"])
|
@bot.message_handler(commands=["start"])
|
||||||
|
|
||||||
def start(m, res=False):
|
def start(m, res=False):
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# Исключения
|
||||||
|
|
||||||
|
try: # Указываем "опасное место"
|
||||||
|
2/0
|
||||||
|
except: # Проверка на все ошибки
|
||||||
|
print('Абшибка')
|
||||||
|
else: # Вывод только если нет ошибок
|
||||||
|
print('Абшибак нет')
|
||||||
|
finally: # Вывод всегда
|
||||||
|
print('А пуфик')
|
||||||