aboutsummaryrefslogtreecommitdiffstats
path: root/botmanager.py
diff options
context:
space:
mode:
authorjantuomi <jans.tuomi@gmail.com>2016-07-18 15:24:13 +0300
committerjantuomi <jans.tuomi@gmail.com>2016-07-18 15:24:13 +0300
commit4c7d083ca70402f9b4f5066e9209a91e555d8638 (patch)
treebe78c2590c3f3ee8aa5687c4e8b0f34dad61b28f /botmanager.py
parent71e97a1b39e5f525f58446a8d851ea5e9d2575ab (diff)
Refactor sending messages to Telegram into its own method
Diffstat (limited to 'botmanager.py')
-rw-r--r--botmanager.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/botmanager.py b/botmanager.py
index 9f18abc..cd74f46 100644
--- a/botmanager.py
+++ b/botmanager.py
@@ -40,12 +40,17 @@ class BotManager(object):
logging.info("Listening for messages...")
while True:
- # TODO send to telegram
- messages = Communicator.fetch(self.shoutbox_api_url)
+ self.forward_to_telegram(Communicator.fetch(self.shoutbox_api_url))
+ time.sleep(10)
+
+ def forward_to_telegram(self, messages):
+ try:
for message in messages:
self.bot.sendMessage(self.telegram_chat_id,
"{}: {}".format(message["user"], message["text"]))
- time.sleep(10)
+ except:
+ logging.warning("Failed to send message to Telegram!")
+ traceback.print_exc()
def default_action(self, chat_id):
self.bot.sendMessage(chat_id, "Radio palaa keväällä 2017!")