diff options
| author | jantuomi <jans.tuomi@gmail.com> | 2016-07-19 14:20:36 +0300 |
|---|---|---|
| committer | jantuomi <jans.tuomi@gmail.com> | 2016-07-19 14:20:36 +0300 |
| commit | 50779b5ecc55f906bcfd46e54dad70b2c74d3a98 (patch) | |
| tree | c3627888448c9e49f32df8670596758f347427b4 /shoutboxapicommunicator.py | |
| parent | eacb313e19805fd8d4bbba1b3515aa9adcd897cf (diff) | |
Code cleanup
Diffstat (limited to 'shoutboxapicommunicator.py')
| -rw-r--r-- | shoutboxapicommunicator.py | 20 |
1 files changed, 13 insertions, 7 deletions
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!") |
