добавил удаление
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-04-19 19:13:57 +10:00
parent 9e6e1e3c98
commit 92cb60aa1d
2 changed files with 30 additions and 3 deletions

View File

@@ -268,6 +268,25 @@ def get_all_sources():
return {"sources": sources}
finally:
pass
def delete_sources(url: str):
"""Удаляет источник по URL из таблицы sourse"""
conn = get_connection()
try:
with conn.cursor() as cur:
cur.execute("DELETE FROM sourse WHERE url=%s RETURNING *", (url,))
deleted_task = cur.fetchone()
conn.commit()
if deleted_task:
return {"message": f"Источник {url} удалён", "deleted": True}
else:
return {"message": f"Источник с url {url} не найден", "deleted": False}
except Exception as e:
print(f"Ошибка при удалении источника: {e}")
return {"error": str(e), "deleted": False}
finally:
pass
# Пример использования
# if __name__ == "__main__":
# # create_table_config_gpt() # <-- раскомментировать эту строку
@@ -278,4 +297,5 @@ def get_all_sources():
# })
# # print(get_promt("japan"))
# # create_table_error_url()
# create_table_add_sourse()
# create_table_add_sourse()
# delete_sources("https://www.taipeitimes.com/")