From 305f1afa3ceaeb6eb34bcb1f83d0ac1294c82133 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Mon, 30 May 2022 00:33:36 +0300 Subject: [PATCH] #7 Moving from package to module. --- bot.py | 2 +- telegram/command_processor.py => telegram.py | 33 +++++++++++++++++++ telegram/__init__.py | 0 telegram/notifier.py | 34 -------------------- 4 files changed, 34 insertions(+), 35 deletions(-) rename telegram/command_processor.py => telegram.py (58%) delete mode 100644 telegram/__init__.py delete mode 100644 telegram/notifier.py diff --git a/bot.py b/bot.py index 22aff3f..3f79158 100644 --- a/bot.py +++ b/bot.py @@ -2,7 +2,7 @@ import logging import os from dotenv import load_dotenv -from telegram.command_processor import CommandProcessor +from telegram import CommandProcessor load_dotenv() diff --git a/telegram/command_processor.py b/telegram.py similarity index 58% rename from telegram/command_processor.py rename to telegram.py index 1081f99..b89075c 100644 --- a/telegram/command_processor.py +++ b/telegram.py @@ -32,3 +32,36 @@ class CommandProcessor: def __delete_feed(self, message: Message): self.bot.reply_to(message, 'Feed deleted: (stub)') + + +class Notifier: + """Sends notifications to users about new RSS feed items.""" + + bot: telebot.TeleBot + + def __init__(self, token: str): + self.bot = telebot.TeleBot(token) + + 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']}" + ) diff --git a/telegram/__init__.py b/telegram/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/telegram/notifier.py b/telegram/notifier.py deleted file mode 100644 index d80dfc9..0000000 --- a/telegram/notifier.py +++ /dev/null @@ -1,34 +0,0 @@ -import telebot - - -class Notifier: - """Sends notifications to users about new RSS feed items.""" - - bot: telebot.TeleBot - - def __init__(self, token: str): - self.bot = telebot.TeleBot(token) - - 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']}" - )