#7 Notifier is now able to process real FeedItem objects.
This commit is contained in:
parent
54cded15e5
commit
882b4df5e1
15
telegram.py
15
telegram.py
|
@ -5,6 +5,7 @@ import validators
|
||||||
|
|
||||||
from database import Database
|
from database import Database
|
||||||
from exceptions import DisplayableException
|
from exceptions import DisplayableException
|
||||||
|
from rss import FeedItem
|
||||||
|
|
||||||
|
|
||||||
class CommandProcessor:
|
class CommandProcessor:
|
||||||
|
@ -90,23 +91,23 @@ class Notifier:
|
||||||
def __init__(self, token: str):
|
def __init__(self, token: str):
|
||||||
self.bot: TeleBot = TeleBot(token)
|
self.bot: TeleBot = TeleBot(token)
|
||||||
|
|
||||||
def send_updates(self, chat_id: int, updates: list):
|
def send_updates(self, chat_id: int, updates: list[FeedItem]):
|
||||||
"""Send notification about new items to the user"""
|
"""Send notification about new items to the user"""
|
||||||
for update in updates:
|
for update in updates:
|
||||||
self.__send_update(chat_id, update)
|
self.__send_update(chat_id, update)
|
||||||
|
|
||||||
def __send_update(self, chat_id: int, update):
|
def __send_update(self, telegram_id: int, update: FeedItem):
|
||||||
self.bot.send_message(
|
self.bot.send_message(
|
||||||
chat_id=chat_id,
|
chat_id=telegram_id,
|
||||||
text=self.__format_message(),
|
text=self.__format_message(update),
|
||||||
parse_mode='MarkdownV2'
|
parse_mode='MarkdownV2'
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __format_message(item) -> str:
|
def __format_message(item: FeedItem) -> str:
|
||||||
return (
|
return (
|
||||||
f"**[{update['title']}]({update['url']})**\n\n"
|
f"**[{item.title}]({item.url})**\n\n"
|
||||||
f"{update['text']}"
|
f"{item.description}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue