diff --git a/telegram.py b/telegram.py index bf39403..fb87c38 100644 --- a/telegram.py +++ b/telegram.py @@ -58,8 +58,8 @@ class CommandProcessor: feeds = self.database.find_user_feeds(data['user_id']) feed_list = '' - for feed in feeds: - feed_list += '* ' + str(feed[0]) + ': ' + feed[1] + '\n' + for count, feed in enumerate(feeds, start=1): + feed_list += '* ' + str(count) + ': ' + feed['url'] + '\n' self.bot.reply_to(message, 'Your feeds:\n' + feed_list) @@ -97,9 +97,13 @@ class Notifier: def __init__(self, token: str): self.bot: TeleBot = TeleBot(token) - def send_updates(self, chat_ids: list[int], updates: list[FeedItem]): + def send_updates(self, chat_ids: list[int], updates: list[FeedItem], feed_title: str): """Send notification about new items to the user""" for chat_id in chat_ids: + self.bot.send_message( + chat_id=chat_id, + text=f'Updates from the {feed_title} feed:' + ) for update in updates: self.__send_update(chat_id, update) self.sent_counter += 1 diff --git a/update_manager.py b/update_manager.py index 81ac61e..a928438 100644 --- a/update_manager.py +++ b/update_manager.py @@ -5,15 +5,16 @@ from telegram import Notifier class UpdateManager: def __init__(self, database: Database, notifier: Notifier, rss_reader: RssReader) -> None: - self.database = database - self.notifier = notifier - self.rss_reader = rss_reader + self.database: Database = database + self.notifier: Notifier = notifier + self.rss_reader: RssReader = rss_reader def update(self): feeds = self.database.find_feeds() for feed_id, feed_url in feeds: - new_items = self.rss_reader.get_feed(feed_url).items + feed = self.rss_reader.get_feed(feed_url) + new_items = feed.items old_items_urls = self.database.find_feed_items_urls(feed_id) diff = self.__calculate_difference(new_items, old_items_urls) @@ -22,7 +23,7 @@ class UpdateManager: continue chat_ids = self.database.find_feed_subscribers(feed_id) - self.notifier.send_updates(chat_ids, diff) + self.notifier.send_updates(chat_ids, diff, feed.title) self.database.update_feed_items(feed_id, new_items) def __calculate_difference(self, new_items: list[FeedItem], old_items_urls: list[str]) -> list[FeedItem]: