From 882b4df5e197f242855f62ee77c7f4883d19028e Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Mon, 30 May 2022 03:33:04 +0300 Subject: [PATCH] #7 Notifier is now able to process real FeedItem objects. --- telegram.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/telegram.py b/telegram.py index f419e57..b456060 100644 --- a/telegram.py +++ b/telegram.py @@ -5,6 +5,7 @@ import validators from database import Database from exceptions import DisplayableException +from rss import FeedItem class CommandProcessor: @@ -90,23 +91,23 @@ class Notifier: def __init__(self, token: str): self.bot: TeleBot = TeleBot(token) - def send_updates(self, chat_id: int, updates: list): + def send_updates(self, chat_id: int, updates: list[FeedItem]): """Send notification about new items to the user""" for update in updates: self.__send_update(chat_id, update) - def __send_update(self, chat_id: int, update): + def __send_update(self, telegram_id: int, update: FeedItem): self.bot.send_message( - chat_id=chat_id, - text=self.__format_message(), + chat_id=telegram_id, + text=self.__format_message(update), parse_mode='MarkdownV2' ) @staticmethod - def __format_message(item) -> str: + def __format_message(item: FeedItem) -> str: return ( - f"**[{update['title']}]({update['url']})**\n\n" - f"{update['text']}" + f"**[{item.title}]({item.url})**\n\n" + f"{item.description}" )