Skip to content

Commit

Permalink
Add notifications of answers
Browse files Browse the repository at this point in the history
  • Loading branch information
ApsiV11 committed Oct 10, 2024
1 parent 73bc834 commit f0ef6ed
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion vaalilakanabot2024.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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"<b>Uusi kysymys Fiirumilla!</b>\n{title}\n{BASE_URL}/t/{slug}/{t_id}"
)
return
if (
str(t_id) in question_posts
and question_posts[str(t_id)]["posts_count"] < posts_count
):
question_posts[str(t_id)]["posts_count"] = posts_count
_save_data("data/question_posts.json", question_posts)
_announce_to_channels(
f"<b>Uusia vastauksia kysymykseen Fiirumilla!</b>\n{title}\n{BASE_URL}/t/{slug}/{t_id}"
)


def _announce_to_channels(message):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f0ef6ed

Please sign in to comment.