try_except_for_tgBot

This commit is contained in:
ada-dmitry
2023-04-20 10:08:14 +03:00
parent 49a7b5b185
commit 86495f2f80
45 changed files with 36 additions and 11 deletions
Binary file not shown.
Binary file not shown.
+1
View File
@@ -2,3 +2,4 @@ hostname = "localhost"
databname = "PythonDB"
username = "postgres"
passw = "Q1w2e3r4"
api = "6285042955:AAEPprYo9K7Ta0RkDcoqO2Z4Ejdw8to1NX0"
Binary file not shown.

Before

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 76 KiB

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 118 KiB

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 95 KiB

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 95 KiB

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 KiB

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 KiB

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 224 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 118 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 118 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 206 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 KiB

After

Width:  |  Height:  |  Size: 206 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 96 KiB

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 KiB

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 120 KiB

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 126 KiB

After

Width:  |  Height:  |  Size: 32 KiB

+15 -6
View File
@@ -3,22 +3,31 @@ 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()
try:
cursor.execute(creat_qwery)
connection.commit()
except psycopg2.errors.DuplicateTable:
print("s")
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()
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()
+10 -5
View File
@@ -3,16 +3,21 @@ 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)
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)
array = list(cursor.fetchall())
bot = telebot.TeleBot('6285042955:AAEPprYo9K7Ta0RkDcoqO2Z4Ejdw8to1NX0')
bot = telebot.TeleBot(config.api)
@bot.message_handler(commands=["start"])
def start(m, res=False):