add docstrings
This commit is contained in:
parent
d25ca99da1
commit
2caa1e0618
|
@ -60,6 +60,7 @@ class Database:
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
|
||||||
def unsubscribe_user_by_url(self, user_id: int, url: str) -> None:
|
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)
|
feed_id = self.find_feed_by_url(url)
|
||||||
if feed_id is None:
|
if feed_id is None:
|
||||||
raise DisplayableException('Feed does not exist')
|
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:
|
def update_feed_items(self, feed_id: int, new_items: list[FeedItem]) -> None:
|
||||||
"""Replace last feed items with a list items that receive."""
|
"""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]
|
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])
|
self.cur.execute('DELETE FROM feeds_last_items WHERE feed_id = ?', [feed_id])
|
||||||
|
|
|
@ -59,7 +59,7 @@ class CommandProcessor:
|
||||||
|
|
||||||
feed_list = ''
|
feed_list = ''
|
||||||
for index, feed in enumerate(feeds, start=1):
|
for index, feed in enumerate(feeds, start=1):
|
||||||
feed_list += '* ' + str(index) + ': ' + f'''<a href="{feed['url']}">{feed['title']}</a''' + '\n'
|
feed_list += '* ' + str(index) + ': ' + f'''<a href="{feed['url']}">{feed['title']}</a>''' + '\n'
|
||||||
|
|
||||||
self.bot.reply_to(message, 'Your feeds:\n' + feed_list)
|
self.bot.reply_to(message, 'Your feeds:\n' + feed_list)
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,15 @@ from telegram import Notifier
|
||||||
|
|
||||||
|
|
||||||
class UpdateManager:
|
class UpdateManager:
|
||||||
|
"""Implement the feed update."""
|
||||||
|
|
||||||
def __init__(self, database: Database, notifier: Notifier, rss_reader: RssReader) -> None:
|
def __init__(self, database: Database, notifier: Notifier, rss_reader: RssReader) -> None:
|
||||||
self.database: Database = database
|
self.database: Database = database
|
||||||
self.notifier: Notifier = notifier
|
self.notifier: Notifier = notifier
|
||||||
self.rss_reader: RssReader = rss_reader
|
self.rss_reader: RssReader = rss_reader
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
"""Send new feed items to the user."""
|
||||||
feeds = self.database.find_feeds()
|
feeds = self.database.find_feeds()
|
||||||
|
|
||||||
for feed_id, feed_url in feeds:
|
for feed_id, feed_url in feeds:
|
||||||
|
@ -27,6 +30,7 @@ class UpdateManager:
|
||||||
self.database.update_feed_items(feed_id, new_items)
|
self.database.update_feed_items(feed_id, new_items)
|
||||||
|
|
||||||
def __calculate_difference(self, new_items: list[FeedItem], old_items_urls: list[str]) -> list[FeedItem]:
|
def __calculate_difference(self, new_items: list[FeedItem], old_items_urls: list[str]) -> list[FeedItem]:
|
||||||
|
"""Calculate new feed items."""
|
||||||
if not old_items_urls:
|
if not old_items_urls:
|
||||||
return new_items
|
return new_items
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue