diff --git a/database.py b/database.py index 9604624..77a9038 100644 --- a/database.py +++ b/database.py @@ -60,6 +60,7 @@ class Database: self.conn.commit() def unsubscribe_user_by_url(self, user_id: int, url: str) -> None: + """Subscribe a user to the feed by url.""" feed_id = self.find_feed_by_url(url) if feed_id is None: raise DisplayableException('Feed does not exist') @@ -128,7 +129,7 @@ class Database: def update_feed_items(self, feed_id: int, new_items: list[FeedItem]) -> None: """Replace last feed items with a list items that receive.""" - for i in range(len(new_items)): + for i, _ in enumerate(new_items): new_items[i] = [feed_id] + list(new_items[i].__dict__.values())[:-1] self.cur.execute('DELETE FROM feeds_last_items WHERE feed_id = ?', [feed_id]) diff --git a/telegram.py b/telegram.py index 4293146..98bfd4f 100644 --- a/telegram.py +++ b/telegram.py @@ -59,7 +59,7 @@ class CommandProcessor: feed_list = '' for index, feed in enumerate(feeds, start=1): - feed_list += '* ' + str(index) + ': ' + f'''{feed['title']}{feed['title']}''' + '\n' self.bot.reply_to(message, 'Your feeds:\n' + feed_list) @@ -105,7 +105,7 @@ class Notifier: text=f'Updates from the {feed_title} feed:' ) self.sent_counter += 1 - + 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 a928438..c8898f2 100644 --- a/update_manager.py +++ b/update_manager.py @@ -4,12 +4,15 @@ from telegram import Notifier class UpdateManager: + """Implement the feed update.""" + def __init__(self, database: Database, notifier: Notifier, rss_reader: RssReader) -> None: self.database: Database = database self.notifier: Notifier = notifier self.rss_reader: RssReader = rss_reader def update(self): + """Send new feed items to the user.""" feeds = self.database.find_feeds() for feed_id, feed_url in feeds: @@ -27,9 +30,10 @@ class UpdateManager: self.database.update_feed_items(feed_id, new_items) def __calculate_difference(self, new_items: list[FeedItem], old_items_urls: list[str]) -> list[FeedItem]: + """Calculate new feed items.""" if not old_items_urls: return new_items - + diff = [] for item in new_items: