minor fixes
This commit is contained in:
parent
42de1efed1
commit
4f25c2dd3f
4
rss.py
4
rss.py
|
@ -9,7 +9,8 @@ class FeedItem:
|
||||||
if 'published' in item:
|
if 'published' in item:
|
||||||
self.date = item.published_parsed()
|
self.date = item.published_parsed()
|
||||||
else:
|
else:
|
||||||
self.date = ''
|
self.date = None
|
||||||
|
|
||||||
|
|
||||||
class Feed:
|
class Feed:
|
||||||
def __init__(self, url: str, feed: FeedParserDict) -> None:
|
def __init__(self, url: str, feed: FeedParserDict) -> None:
|
||||||
|
@ -19,6 +20,7 @@ class Feed:
|
||||||
for item in feed.entries:
|
for item in feed.entries:
|
||||||
self.items.append(FeedItem(item))
|
self.items.append(FeedItem(item))
|
||||||
|
|
||||||
|
|
||||||
class RssReader:
|
class RssReader:
|
||||||
def get_feed(self, url: str) -> Feed:
|
def get_feed(self, url: str) -> Feed:
|
||||||
return Feed(url, parse(url))
|
return Feed(url, parse(url))
|
||||||
|
|
12
telegram.py
12
telegram.py
|
@ -58,8 +58,8 @@ class CommandProcessor:
|
||||||
feeds = self.database.find_user_feeds(data['user_id'])
|
feeds = self.database.find_user_feeds(data['user_id'])
|
||||||
|
|
||||||
feed_list = ''
|
feed_list = ''
|
||||||
for count, feed in enumerate(feeds, start=1):
|
for index, feed in enumerate(feeds, start=1):
|
||||||
feed_list += '* ' + str(count) + ': ' + feed['url'] + '\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)
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ class CommandProcessor:
|
||||||
class Notifier:
|
class Notifier:
|
||||||
"""Sends notifications to users about new RSS feed items."""
|
"""Sends notifications to users about new RSS feed items."""
|
||||||
|
|
||||||
BATCH_LIMIT: int = 30
|
BATCH_LIMIT: int = 29
|
||||||
|
|
||||||
sent_counter: int = 0
|
sent_counter: int = 0
|
||||||
|
|
||||||
|
@ -104,6 +104,8 @@ class Notifier:
|
||||||
chat_id=chat_id,
|
chat_id=chat_id,
|
||||||
text=f'Updates from the {feed_title} feed:'
|
text=f'Updates from the {feed_title} feed:'
|
||||||
)
|
)
|
||||||
|
self.sent_counter += 1
|
||||||
|
|
||||||
for update in updates:
|
for update in updates:
|
||||||
self.__send_update(chat_id, update)
|
self.__send_update(chat_id, update)
|
||||||
self.sent_counter += 1
|
self.sent_counter += 1
|
||||||
|
@ -123,8 +125,8 @@ class Notifier:
|
||||||
def __format_message(item: FeedItem) -> str:
|
def __format_message(item: FeedItem) -> str:
|
||||||
return (
|
return (
|
||||||
f"<strong><a href=\"{item.url}\">{item.title}</a></strong>\n\n"
|
f"<strong><a href=\"{item.url}\">{item.title}</a></strong>\n\n"
|
||||||
f"{item.description}\n"
|
f"{item.date}\n"
|
||||||
f"{item.date}"
|
f"{item.description}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue