From 427bb4222ad7312ce38165ac885e12f652a5e0a8 Mon Sep 17 00:00:00 2001 From: norohind <60548839+norohind@users.noreply.github.com> Date: Sat, 27 Nov 2021 01:12:43 +0300 Subject: [PATCH] Fix news diff --- sql_requests.py | 2 +- utils.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/sql_requests.py b/sql_requests.py index 288bc06..7fae8a4 100644 --- a/sql_requests.py +++ b/sql_requests.py @@ -100,7 +100,7 @@ limit 2;""" # limit 2;""" select_new_old_news: str = """select {column} from news -where squad_id = ? and category = 'Squadrons_History_Category_PublicStatement' +where squad_id = ? and type_of_news = 'public_statements' order by inserted_timestamp desc limit 2;""" diff --git a/utils.py b/utils.py index 10c44e4..f63609f 100644 --- a/utils.py +++ b/utils.py @@ -238,6 +238,19 @@ def _update_squad_news(squad_id: int, db_conn: sqlite3.Connection) -> Union[bool for type_of_news_key in squad_news: one_type_of_news: list = squad_news[type_of_news_key] + if len(squad_news[type_of_news_key]) == 0: + logger.info(f'squad_news[{type_of_news_key}] len == 0') + + with db_conn: + db_conn.execute( + sql_requests.insert_news, + ( + squad_id, + type_of_news_key, + *[None for i in range(0, 10)] + ) + ) + news: dict for news in one_type_of_news: with db_conn: