добавил новые поля и работу с донесениями
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:
14
parser_bd.py
14
parser_bd.py
@@ -13,6 +13,10 @@ class ParsedData(BaseModel):
|
||||
article_date: str
|
||||
status: Optional[bool] = False
|
||||
viewed: Optional[bool] = False
|
||||
tematik: Optional[bool] = False
|
||||
svodka: Optional[bool] = False
|
||||
donesenie: Optional[bool] = False
|
||||
bilutene: Optional[bool] = False
|
||||
other: str
|
||||
category: str
|
||||
translation_text: str
|
||||
@@ -34,8 +38,8 @@ def save_parsed_data_to_db(data: ParsedData):
|
||||
conn = get_connection()
|
||||
with conn.cursor() as cur:
|
||||
cur.execute("""
|
||||
INSERT INTO url (url, parsed_at, title, original_text, article_date, status, viewed, other, category, translation_text, short_text)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
INSERT INTO url (url, parsed_at, title, original_text, article_date, status, viewed, tematik, svodka, donesenie, bilutene, other, category, translation_text, short_text)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
ON CONFLICT (url) DO UPDATE SET
|
||||
parsed_at = EXCLUDED.parsed_at,
|
||||
title = EXCLUDED.title,
|
||||
@@ -43,11 +47,15 @@ def save_parsed_data_to_db(data: ParsedData):
|
||||
article_date = EXCLUDED.article_date,
|
||||
status = EXCLUDED.status,
|
||||
viewed = EXCLUDED.viewed,
|
||||
tematik = EXCLUDED.tematik,
|
||||
svodka = EXCLUDED.svodka,
|
||||
donesenie = EXCLUDED.donesenie,
|
||||
bilutene = EXCLUDED.bilutene,
|
||||
other = EXCLUDED.other,
|
||||
category = EXCLUDED.category,
|
||||
translation_text = EXCLUDED.translation_text,
|
||||
short_text = EXCLUDED.short_text;
|
||||
""", (data.url, data.parsed_at, data.title, data.original_text, data.article_date, data.status, data.viewed, data.other, data.category, data.translation_text, data.short_text))
|
||||
""", (data.url, data.parsed_at, data.title, data.original_text, data.article_date, data.status, data.viewed, data.tematik, data.svodka, data.donesenie, data.bilutene, data.other, data.category, data.translation_text, data.short_text))
|
||||
conn.commit()
|
||||
return {"status": "success", "message": "Данные успешно сохранены"}
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user