minor fixes
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is failing Details

This commit is contained in:
mitsuha_s 2022-07-04 18:38:23 +00:00
parent 42de1efed1
commit 4f25c2dd3f
3 changed files with 11 additions and 7 deletions

4
rss.py
View File

@ -9,7 +9,8 @@ class FeedItem:
if 'published' in item:
self.date = item.published_parsed()
else:
self.date = ''
self.date = None
class Feed:
def __init__(self, url: str, feed: FeedParserDict) -> None:
@ -19,6 +20,7 @@ class Feed:
for item in feed.entries:
self.items.append(FeedItem(item))
class RssReader:
def get_feed(self, url: str) -> Feed:
return Feed(url, parse(url))

View File

@ -58,8 +58,8 @@ class CommandProcessor:
feeds = self.database.find_user_feeds(data['user_id'])
feed_list = ''
for count, feed in enumerate(feeds, start=1):
feed_list += '* ' + str(count) + ': ' + feed['url'] + '\n'
for index, feed in enumerate(feeds, start=1):
feed_list += '* ' + str(index) + ': ' + f"<a href={feed['url']}>{feed['title']}</a" + '\n'
self.bot.reply_to(message, 'Your feeds:\n' + feed_list)
@ -90,7 +90,7 @@ class CommandProcessor:
class Notifier:
"""Sends notifications to users about new RSS feed items."""
BATCH_LIMIT: int = 30
BATCH_LIMIT: int = 29
sent_counter: int = 0
@ -104,6 +104,8 @@ class Notifier:
chat_id=chat_id,
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
@ -123,8 +125,8 @@ class Notifier:
def __format_message(item: FeedItem) -> str:
return (
f"<strong><a href=\"{item.url}\">{item.title}</a></strong>\n\n"
f"{item.description}\n"
f"{item.date}"
f"{item.date}\n"
f"{item.description}"
)

View File

@ -12,4 +12,4 @@ notifier = Notifier(token)
rss_reader = RssReader()
updater = UpdateManager(db, notifier, rss_reader)
updater.update()
updater.update()