diff options
| -rw-r--r-- | botmanager.py | 7 | ||||
| -rw-r--r-- | jsonfactory.py | 6 | ||||
| -rw-r--r-- | mockshoutbox.py | 2 |
3 files changed, 11 insertions, 4 deletions
diff --git a/botmanager.py b/botmanager.py index 4d3fd86..9f18abc 100644 --- a/botmanager.py +++ b/botmanager.py @@ -41,7 +41,10 @@ class BotManager(object): logging.info("Listening for messages...") while True: # TODO send to telegram - Communicator.fetch(self.shoutbox_api_url) + messages = Communicator.fetch(self.shoutbox_api_url) + for message in messages: + self.bot.sendMessage(self.telegram_chat_id, + "{}: {}".format(message["user"], message["text"])) time.sleep(10) def default_action(self, chat_id): @@ -68,7 +71,7 @@ class BotManager(object): self.not_supported(chat_id) elif str(chat_id) == self.telegram_chat_id.strip(): user_name = msg["from"]["first_name"] - data = JSONFactory.make(t, user_name, msg["date"], "null") + data = JSONFactory.make_object(t, user_name, msg["date"], "null") logging.info("Created JSON packet:\n{}".format(data)) Communicator.send(self.shoutbox_api_url, data) else: diff --git a/jsonfactory.py b/jsonfactory.py index 7cb316c..be70996 100644 --- a/jsonfactory.py +++ b/jsonfactory.py @@ -3,7 +3,7 @@ import json class JSONFactory(object): @staticmethod - def make(text, user, timestamp, ip): + def make_object(text, user, timestamp, ip): message = json.dumps({ "text": text, "user": user, @@ -12,3 +12,7 @@ class JSONFactory(object): }) return message + + @staticmethod + def make_array(object_list): + return "[\n" + ",\n".join(object_list) + "\n]" diff --git a/mockshoutbox.py b/mockshoutbox.py index 7ab1bbc..6e6326e 100644 --- a/mockshoutbox.py +++ b/mockshoutbox.py @@ -42,7 +42,7 @@ class MyHandler(SimpleHTTPRequestHandler): # Begin the response self.send_response(200) - except KeyError: + except: traceback.print_exc() self.send_response(400) |
