From 50779b5ecc55f906bcfd46e54dad70b2c74d3a98 Mon Sep 17 00:00:00 2001 From: jantuomi Date: Tue, 19 Jul 2016 14:20:36 +0300 Subject: Code cleanup --- shoutboxapicommunicator.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'shoutboxapicommunicator.py') diff --git a/shoutboxapicommunicator.py b/shoutboxapicommunicator.py index 28a5b74..7138aa9 100644 --- a/shoutboxapicommunicator.py +++ b/shoutboxapicommunicator.py @@ -1,15 +1,20 @@ import json - import requests import logging +from basecommunicator import BaseCommunicator + +class ShoutboxCommunicator(BaseCommunicator): + """Class for communication with the shoutbox API""" -class Communicator(object): + url = "http://localhost:8000" + interval = 10 @staticmethod - def fetch(url): + def fetch(): + """Get and return a list of new messages from the API""" try: - r = requests.get(url) + r = requests.get(ShoutboxCommunicator.url) logging.info("Response from API OK.") except: @@ -24,10 +29,11 @@ class Communicator(object): return content @staticmethod - def send(url, data): + def send(data): + """Send a JSON message to the API""" try: - requests.post(url, data) + requests.post(ShoutboxCommunicator.url, data) user = json.loads(data)["user"] logging.info("Sent message from {} to shoutbox.".format(user)) except: - logging.warning("Failed to send message to shoutbox API!") \ No newline at end of file + logging.warning("Failed to send message to shoutbox API!") -- cgit v1.3