diff --git a/main.py b/main.py index 7e6c9b7..fed947d 100644 --- a/main.py +++ b/main.py @@ -211,6 +211,32 @@ def get_records(): if conn: conn.close() +@app.get("/records_all_status", summary="Получить все записи избранного", response_model=List[ParsedData]) +def get_records(): + """ + Возвращает записи из таблицы url с избранным. + """ + conn = None + try: + conn = get_connection() + with conn.cursor(cursor_factory=psycopg2.extras.DictCursor) as cur: + cur.execute(""" + SELECT url, parsed_at, title, original_text, article_date, status, viewed, other, category, translation_text, short_text + FROM url + WHERE status = true + ORDER BY parsed_at DESC + """) + rows = cur.fetchall() + results = [dict(row) for row in rows] + urls = [item['parsed_at'] for item in results] + + print(urls) + return results + except Exception as e: + raise HTTPException(status_code=500, detail=f"Ошибка при получении записей из БД: {e}") + finally: + if conn: + conn.close() # get_records()