2022-05-01 23:43:04 +00:00
|
|
|
import telebot
|
|
|
|
|
|
|
|
|
|
|
|
class Notifier:
|
2022-05-02 15:18:13 +00:00
|
|
|
"""Sends notifications to users about new RSS feed items."""
|
2022-05-02 14:53:53 +00:00
|
|
|
|
2022-05-01 23:43:04 +00:00
|
|
|
bot: telebot.TeleBot
|
|
|
|
|
|
|
|
def __init__(self, token: str):
|
|
|
|
self.bot = telebot.TeleBot(token)
|
|
|
|
|
2022-05-02 20:41:17 +00:00
|
|
|
def send_updates(self, chat_id: int, updates: list):
|
|
|
|
"""Send notification about new items to the user"""
|
|
|
|
for update in updates:
|
|
|
|
self.__send_update(chat_id, update)
|
|
|
|
|
|
|
|
def __send_update(self, chat_id: int, update):
|
|
|
|
self.bot.send_message(
|
|
|
|
chat_id=chat_id,
|
|
|
|
text=self.__format_message(),
|
|
|
|
parse_mode='MarkdownV2'
|
|
|
|
)
|
|
|
|
|
|
|
|
def __format_message(self) -> str:
|
|
|
|
update = {
|
|
|
|
'title': 'Item Title',
|
|
|
|
'text': 'Short item text here...',
|
|
|
|
'url': 'https://fediland.github.io/',
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
f"**[{update['title']}]({update['url']})**\n\n"
|
|
|
|
f"{update['text']}"
|
|
|
|
)
|