diff --git a/Python/TeleBot/__pycache__/config.cpython-311.pyc b/Python/TeleBot/__pycache__/config.cpython-311.pyc index 0171f87..dd0b1e1 100644 Binary files a/Python/TeleBot/__pycache__/config.cpython-311.pyc and b/Python/TeleBot/__pycache__/config.cpython-311.pyc differ diff --git a/Python/TeleBot/__pycache__/parser.cpython-311.pyc b/Python/TeleBot/__pycache__/parser.cpython-311.pyc index 17b715b..0e879ce 100644 Binary files a/Python/TeleBot/__pycache__/parser.cpython-311.pyc and b/Python/TeleBot/__pycache__/parser.cpython-311.pyc differ diff --git a/Python/TeleBot/__pycache__/tableCreator.cpython-311.pyc b/Python/TeleBot/__pycache__/tableCreator.cpython-311.pyc index f906620..4bee6ba 100644 Binary files a/Python/TeleBot/__pycache__/tableCreator.cpython-311.pyc and b/Python/TeleBot/__pycache__/tableCreator.cpython-311.pyc differ diff --git a/Python/TeleBot/config.py b/Python/TeleBot/config.py index 8a59dfc..e9e6b3a 100644 --- a/Python/TeleBot/config.py +++ b/Python/TeleBot/config.py @@ -2,3 +2,4 @@ hostname = "localhost" databname = "PythonDB" username = "postgres" passw = "Q1w2e3r4" +api = "6285042955:AAEPprYo9K7Ta0RkDcoqO2Z4Ejdw8to1NX0" \ No newline at end of file diff --git a/Python/TeleBot/img/0 (1).jpg b/Python/TeleBot/img/0 (1).jpg deleted file mode 100644 index 49bd483..0000000 Binary files a/Python/TeleBot/img/0 (1).jpg and /dev/null differ diff --git a/Python/TeleBot/img/0.jpg b/Python/TeleBot/img/0.jpg index a3605fb..49bd483 100644 Binary files a/Python/TeleBot/img/0.jpg and b/Python/TeleBot/img/0.jpg differ diff --git a/Python/TeleBot/img/1 (1).jpg b/Python/TeleBot/img/1 (1).jpg deleted file mode 100644 index 04e47ef..0000000 Binary files a/Python/TeleBot/img/1 (1).jpg and /dev/null differ diff --git a/Python/TeleBot/img/1.jpg b/Python/TeleBot/img/1.jpg index c7aea3b..04e47ef 100644 Binary files a/Python/TeleBot/img/1.jpg and b/Python/TeleBot/img/1.jpg differ diff --git a/Python/TeleBot/img/10 (1).jpg b/Python/TeleBot/img/10 (1).jpg deleted file mode 100644 index 697228c..0000000 Binary files a/Python/TeleBot/img/10 (1).jpg and /dev/null differ diff --git a/Python/TeleBot/img/10.jpg b/Python/TeleBot/img/10.jpg index 2dccefe..697228c 100644 Binary files a/Python/TeleBot/img/10.jpg and b/Python/TeleBot/img/10.jpg differ diff --git a/Python/TeleBot/img/11 (1).jpg b/Python/TeleBot/img/11 (1).jpg deleted file mode 100644 index 0eeeff9..0000000 Binary files a/Python/TeleBot/img/11 (1).jpg and /dev/null differ diff --git a/Python/TeleBot/img/11.jpg b/Python/TeleBot/img/11.jpg index 7688e9c..0eeeff9 100644 Binary files a/Python/TeleBot/img/11.jpg and b/Python/TeleBot/img/11.jpg differ diff --git a/Python/TeleBot/img/12 (1).jpg b/Python/TeleBot/img/12 (1).jpg deleted file mode 100644 index 1f7bdb9..0000000 Binary files a/Python/TeleBot/img/12 (1).jpg and /dev/null differ diff --git a/Python/TeleBot/img/12.jpg b/Python/TeleBot/img/12.jpg index c7c0cb4..1f7bdb9 100644 Binary files a/Python/TeleBot/img/12.jpg and b/Python/TeleBot/img/12.jpg differ diff --git a/Python/TeleBot/img/13 (1).jpg b/Python/TeleBot/img/13 (1).jpg deleted file mode 100644 index 46ff547..0000000 Binary files a/Python/TeleBot/img/13 (1).jpg and /dev/null differ diff --git a/Python/TeleBot/img/13.jpg b/Python/TeleBot/img/13.jpg index 4c1bf3b..46ff547 100644 Binary files a/Python/TeleBot/img/13.jpg and b/Python/TeleBot/img/13.jpg differ diff --git a/Python/TeleBot/img/14 (1).jpg b/Python/TeleBot/img/14 (1).jpg deleted file mode 100644 index d79d495..0000000 Binary files a/Python/TeleBot/img/14 (1).jpg and /dev/null differ diff --git a/Python/TeleBot/img/14.jpg b/Python/TeleBot/img/14.jpg index bafbe29..d79d495 100644 Binary files a/Python/TeleBot/img/14.jpg and b/Python/TeleBot/img/14.jpg differ diff --git a/Python/TeleBot/img/15 (1).jpg b/Python/TeleBot/img/15 (1).jpg deleted file mode 100644 index 7a38c3b..0000000 Binary files a/Python/TeleBot/img/15 (1).jpg and /dev/null differ diff --git a/Python/TeleBot/img/15.jpg b/Python/TeleBot/img/15.jpg deleted file mode 100644 index dd5057e..0000000 Binary files a/Python/TeleBot/img/15.jpg and /dev/null differ diff --git a/Python/TeleBot/img/16 (1).jpg b/Python/TeleBot/img/16 (1).jpg deleted file mode 100644 index caa4c17..0000000 Binary files a/Python/TeleBot/img/16 (1).jpg and /dev/null differ diff --git a/Python/TeleBot/img/16.jpg b/Python/TeleBot/img/16.jpg deleted file mode 100644 index 9b8b34a..0000000 Binary files a/Python/TeleBot/img/16.jpg and /dev/null differ diff --git a/Python/TeleBot/img/17 (1).jpg b/Python/TeleBot/img/17 (1).jpg deleted file mode 100644 index d79d495..0000000 Binary files a/Python/TeleBot/img/17 (1).jpg and /dev/null differ diff --git a/Python/TeleBot/img/17.jpg b/Python/TeleBot/img/17.jpg deleted file mode 100644 index d79d495..0000000 Binary files a/Python/TeleBot/img/17.jpg and /dev/null differ diff --git a/Python/TeleBot/img/18 (1).jpg b/Python/TeleBot/img/18 (1).jpg deleted file mode 100644 index 223746c..0000000 Binary files a/Python/TeleBot/img/18 (1).jpg and /dev/null differ diff --git a/Python/TeleBot/img/18.jpg b/Python/TeleBot/img/18.jpg deleted file mode 100644 index 223746c..0000000 Binary files a/Python/TeleBot/img/18.jpg and /dev/null differ diff --git a/Python/TeleBot/img/2 (1).jpg b/Python/TeleBot/img/2 (1).jpg deleted file mode 100644 index c7aea3b..0000000 Binary files a/Python/TeleBot/img/2 (1).jpg and /dev/null differ diff --git a/Python/TeleBot/img/2.jpg b/Python/TeleBot/img/2.jpg index c95a406..c7aea3b 100644 Binary files a/Python/TeleBot/img/2.jpg and b/Python/TeleBot/img/2.jpg differ diff --git a/Python/TeleBot/img/3 (1).jpg b/Python/TeleBot/img/3 (1).jpg deleted file mode 100644 index 083cde9..0000000 Binary files a/Python/TeleBot/img/3 (1).jpg and /dev/null differ diff --git a/Python/TeleBot/img/3.jpg b/Python/TeleBot/img/3.jpg index 0aab9e3..083cde9 100644 Binary files a/Python/TeleBot/img/3.jpg and b/Python/TeleBot/img/3.jpg differ diff --git a/Python/TeleBot/img/4 (1).jpg b/Python/TeleBot/img/4 (1).jpg deleted file mode 100644 index ceb59fe..0000000 Binary files a/Python/TeleBot/img/4 (1).jpg and /dev/null differ diff --git a/Python/TeleBot/img/4.jpg b/Python/TeleBot/img/4.jpg index 576bce6..ceb59fe 100644 Binary files a/Python/TeleBot/img/4.jpg and b/Python/TeleBot/img/4.jpg differ diff --git a/Python/TeleBot/img/5 (1).jpg b/Python/TeleBot/img/5 (1).jpg deleted file mode 100644 index 4c1bf3b..0000000 Binary files a/Python/TeleBot/img/5 (1).jpg and /dev/null differ diff --git a/Python/TeleBot/img/5.jpg b/Python/TeleBot/img/5.jpg index a7c53ab..4c1bf3b 100644 Binary files a/Python/TeleBot/img/5.jpg and b/Python/TeleBot/img/5.jpg differ diff --git a/Python/TeleBot/img/6 (1).jpg b/Python/TeleBot/img/6 (1).jpg deleted file mode 100644 index 9417469..0000000 Binary files a/Python/TeleBot/img/6 (1).jpg and /dev/null differ diff --git a/Python/TeleBot/img/6.jpg b/Python/TeleBot/img/6.jpg index 4b3ea13..9417469 100644 Binary files a/Python/TeleBot/img/6.jpg and b/Python/TeleBot/img/6.jpg differ diff --git a/Python/TeleBot/img/7 (1).jpg b/Python/TeleBot/img/7 (1).jpg deleted file mode 100644 index bafbe29..0000000 Binary files a/Python/TeleBot/img/7 (1).jpg and /dev/null differ diff --git a/Python/TeleBot/img/7.jpg b/Python/TeleBot/img/7.jpg index 2cd8120..bafbe29 100644 Binary files a/Python/TeleBot/img/7.jpg and b/Python/TeleBot/img/7.jpg differ diff --git a/Python/TeleBot/img/8 (1).jpg b/Python/TeleBot/img/8 (1).jpg deleted file mode 100644 index 0672188..0000000 Binary files a/Python/TeleBot/img/8 (1).jpg and /dev/null differ diff --git a/Python/TeleBot/img/8.jpg b/Python/TeleBot/img/8.jpg index a22eee2..0672188 100644 Binary files a/Python/TeleBot/img/8.jpg and b/Python/TeleBot/img/8.jpg differ diff --git a/Python/TeleBot/img/9 (1).jpg b/Python/TeleBot/img/9 (1).jpg deleted file mode 100644 index a7c53ab..0000000 Binary files a/Python/TeleBot/img/9 (1).jpg and /dev/null differ diff --git a/Python/TeleBot/img/9.jpg b/Python/TeleBot/img/9.jpg index ceb59fe..a7c53ab 100644 Binary files a/Python/TeleBot/img/9.jpg and b/Python/TeleBot/img/9.jpg differ diff --git a/Python/TeleBot/tableCreator.py b/Python/TeleBot/tableCreator.py index 39c28e2..baf8903 100644 --- a/Python/TeleBot/tableCreator.py +++ b/Python/TeleBot/tableCreator.py @@ -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() diff --git a/Python/TeleBot/tgBot.py b/Python/TeleBot/tgBot.py index 4bab651..868766b 100644 --- a/Python/TeleBot/tgBot.py +++ b/Python/TeleBot/tgBot.py @@ -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): diff --git a/Work_with_files/main.py b/Work_with_files/main.py new file mode 100644 index 0000000..7a43d6e --- /dev/null +++ b/Work_with_files/main.py @@ -0,0 +1,10 @@ +# Исключения + +try: # Указываем "опасное место" + 2/0 +except: # Проверка на все ошибки + print('Абшибка') +else: # Вывод только если нет ошибок + print('Абшибак нет') +finally: # Вывод всегда + print('А пуфик') \ No newline at end of file