From be7b042e7c45182554d3f524bf3fa9d00b1243c1 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 11 Apr 2026 20:27:48 +1000 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=B2=D0=B5=D0=BB=20ch?= =?UTF-8?q?ek=5Furl=20=D0=B2=20=D0=B1=D0=B0=D0=B7=D1=83=20=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D1=85=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=B0,=20=D1=82=D0=BE=20=D0=B1=D1=8B=20=D0=BD=D0=B5=20=D0=B2?= =?UTF-8?q?=D0=B7=D0=B0=D0=B8=D0=BC=D0=BE=D0=B4=D0=B5=D0=B9=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20=D1=81=D0=BE=20=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BE=D0=BD=D0=BD=D0=B8=D0=BC=20=D1=81=D0=B5?= =?UTF-8?q?=D1=80=D0=B2=D0=B8=D1=81=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 2 +- work_parser.py | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 421d263..adec069 100644 --- a/main.py +++ b/main.py @@ -233,7 +233,7 @@ def gpt_response_message(content: str, name_promt: str): # Общие функции проверки ссылок def check_url(url): try: - response = requests.get('http://45.129.78.228:8002/check_url_exists', params={'url': url}) + response = wp.check_url_exists(url) #get('http://45.129.78.228:8002/check_url_exists', params={'url': url}) if response.status_code == 200: result = response.json() print(result["exists"]) diff --git a/work_parser.py b/work_parser.py index 01a9ae6..9336aa4 100644 --- a/work_parser.py +++ b/work_parser.py @@ -21,13 +21,23 @@ def get_connection(): conn = psycopg2.connect(**DB_CONFIG) conn.autocommit = True return conn +# Проверяет, есть ли указанный URL в базе данных. +def check_url_exists(url: str): + conn = get_connection() + try: + conn = get_connection() + with conn.cursor() as cursor: + cursor.execute( + "SELECT 1 FROM url WHERE url = %s LIMIT 1", + (url,) + ) + result = cursor.fetchone() + return {"exists": bool(result)} + except Exception as e: + raise HTTPException(status_code=500, detail=f"Ошибка при проверке: {e}") + finally: + pass -def close_connection(): - """Закрывает подключение к БД""" - global conn - if conn: - conn.close() - conn = None # работа с базой данных показывания задач work_parser def create_table(): conn = get_connection()