перевел chek_url в базу данных проекта, то бы не взаимодействовать со сторонним сервисом
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user