diff options
| author | jantuomi <jans.tuomi@gmail.com> | 2016-07-19 14:50:22 +0300 |
|---|---|---|
| committer | jantuomi <jans.tuomi@gmail.com> | 2016-07-19 14:50:22 +0300 |
| commit | 9d94a01b631676b54f680c2571ae4dbba9ccd037 (patch) | |
| tree | 2cac58eba2cd5d29ae0c2192efc5ca365dde7f74 /shoutboxapicommunicator.py | |
| parent | 080cfd6cfe946e243239af201dea8466abaee020 (diff) | |
Restructure project
Diffstat (limited to 'shoutboxapicommunicator.py')
| -rw-r--r-- | shoutboxapicommunicator.py | 39 |
1 files changed, 0 insertions, 39 deletions
diff --git a/shoutboxapicommunicator.py b/shoutboxapicommunicator.py deleted file mode 100644 index 7138aa9..0000000 --- a/shoutboxapicommunicator.py +++ /dev/null @@ -1,39 +0,0 @@ -import json -import requests -import logging -from basecommunicator import BaseCommunicator - - -class ShoutboxCommunicator(BaseCommunicator): - """Class for communication with the shoutbox API""" - - url = "http://localhost:8000" - interval = 10 - - @staticmethod - def fetch(): - """Get and return a list of new messages from the API""" - try: - r = requests.get(ShoutboxCommunicator.url) - logging.info("Response from API OK.") - - except: - logging.warning("Failed to get response from API!") - return - - content = json.loads(r.text) - logging.info("Messages:") - for msg in content: - logging.info("{}: {}".format(msg["user"], msg["text"])) - - return content - - @staticmethod - def send(data): - """Send a JSON message to the API""" - try: - 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!") |
