Update manager #23

Merged
Miroslavsckaya merged 20 commits from feature_rss_update into master 2022-07-08 19:23:12 +00:00
Showing only changes of commit 8a4bec01c1 - Show all commits

View file

@ -90,7 +90,7 @@ class CommandProcessor:
class Notifier:
"""Sends notifications to users about new RSS feed items."""
BATCH_LIMIT: int = 29
BATCH_LIMIT: int = 30
sent_counter: int = 0
@ -99,7 +99,11 @@ class Notifier:
def send_updates(self, chat_ids: list[int], updates: list[FeedItem], feed_title: str):
"""Send notification about new items to the user"""
if not updates:
return
for chat_id in chat_ids:
self.__register_request_and_wait()
self.bot.send_message(
chat_id=chat_id,
text=f'Updates from the {feed_title} feed:'
@ -107,12 +111,9 @@ class Notifier:
self.sent_counter += 1
for update in updates:
self.__register_request_and_wait()
self.__send_update(chat_id, update)
self.sent_counter += 1
if self.sent_counter >= self.BATCH_LIMIT:
# TODO: probably implement better later
time.sleep(1)
self.sent_counter = 0
def __send_update(self, chat_id: int, update: FeedItem):
self.bot.send_message(
@ -121,6 +122,12 @@ class Notifier:
parse_mode='HTML'
)
def __register_request_and_wait(self):
if self.sent_counter >= self.BATCH_LIMIT:
# TODO: probably implement better later
time.sleep(1)
self.sent_counter = 0
@staticmethod
def __format_message(item: FeedItem) -> str:
return (