From a8f07027f4b4a3b7436e36a9a32aea2382cbdd9a Mon Sep 17 00:00:00 2001 From: Aapo Laakkio Date: Thu, 10 Oct 2024 20:27:39 +0300 Subject: [PATCH] Add notifications of answers --- vaalilakanabot2024.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/vaalilakanabot2024.py b/vaalilakanabot2024.py index 399a470..daa0c46 100644 --- a/vaalilakanabot2024.py +++ b/vaalilakanabot2024.py @@ -67,7 +67,7 @@ data = f.read() question_posts = json.loads(data) -logger.info("Loaded question posts: %s", fiirumi_posts) +logger.info("Loaded question posts: %s", question_posts) updater = Updater(TOKEN, use_context=True) @@ -162,17 +162,29 @@ def parse_fiirumi_posts(context=updater.bot): t_id = question["id"] title = question["title"] slug = question["slug"] + posts_count = question["posts_count"] if str(t_id) not in question_posts: new_question = { "id": t_id, "title": title, "slug": slug, + "posts_count": posts_count, } question_posts[str(t_id)] = new_question _save_data("data/question_posts.json", question_posts) _announce_to_channels( f"Uusi kysymys Fiirumilla!\n{title}\n{BASE_URL}/t/{slug}/{t_id}" ) + return + + if str(t_id) in question_posts: + has_new_posts = posts_count > question_posts[str(t_id)]["posts_count"] + question_posts[str(t_id)]["posts_count"] = posts_count + _save_data("data/question_posts.json", question_posts) + if has_new_posts: + _announce_to_channels( + f"Uusia vastauksia kysymykseen Fiirumilla!\n{title}\n{BASE_URL}/t/{slug}/{t_id}" + ) def _announce_to_channels(message): @@ -582,6 +594,7 @@ def jauh(update, context): except Exception as e: logger.warning("Error in sending Jauh %s", e) + def jauho(update, context): try: chat_id = update.message.chat.id