расширение выгрузки
All checks were successful
continuous-integration/drone/push Build is passing

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-05-01 23:33:40 +10:00
parent 994479fd9d
commit 8f86c51d19
3 changed files with 52 additions and 3 deletions

View File

@@ -66,6 +66,38 @@ def save_parsed_data_to_db(data: ParsedData):
if conn:
conn.close()
def get_articles_by_filter(field_name: str, start_date: str, finish_date: str):
"""
Возвращает список заголовков статей по полю и диапазону дат
Args:
field_name: имя поля (tematik, svodka, donesenie, bilutene, status)
start_date: дата начала в формате YYYY-MM-DD
finish_date: дата окончания в формате YYYY-MM-DD
Returns:
List[str]: список заголовков (title)
"""
conn = get_connection()
try:
# Проверка валидности поля
allowed_fields = ['tematik', 'svodka', 'donesenie', 'bilutene', 'status']
if field_name not in allowed_fields:
raise ValueError(f"Недопустимое поле: {field_name}. Разрешено: {allowed_fields}")
with conn.cursor(cursor_factory=RealDictCursor) as cur:
cur.execute(f"""
SELECT title FROM url
WHERE {field_name} = TRUE
AND article_date BETWEEN %s AND %s
ORDER BY article_date DESC;
""", (start_date, finish_date))
rows = cur.fetchall()
return [row['title'] for row in rows]
finally:
pass
# Глобальное подключение к БД
conn = None