dweet fix again
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
from state.dweet_server import DweetServer
|
||||
import config
|
||||
import commands
|
||||
|
||||
server = DweetServer(config.CONTROLLER_ID)
|
||||
server.send_message("I am aliveeee (again)!");
|
||||
|
||||
command = """curl -H "Content-Type: application/json" -X POST -d '{"message": "I am aliveeee (again!)", "controller_id": %s}' https://dweet.io:443/dweet/quietly/for/5410ab1e-319c-4f14-a2e4-04725df69121""" % config.CONTROLLER_ID
|
||||
|
||||
print commands.getoutput(command)
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
import json
|
||||
import requests
|
||||
|
||||
|
||||
DWEET_UID = "5410ab1e-319c-4f14-a2e4-04725df69121"
|
||||
|
||||
class DweetServer(object):
|
||||
"Gets state from server and sends it to the server after change"
|
||||
def __init__(self, controller_id=None):
|
||||
self.url_base = "https://dweet.io:443/dweet/quietly/for/%s" % DWEET_UID
|
||||
self.controller_id = controller_id
|
||||
|
||||
def send_message(self, message):
|
||||
result = requests.post(self.full_url(),
|
||||
json=json.dumps({
|
||||
'controller_id': self.controller_id,
|
||||
'message': message
|
||||
}))
|
||||
return handle_response(result)
|
||||
|
||||
def full_url(self):
|
||||
if self.controller_id is None:
|
||||
raise ClassNotReadyException("Controller id not set!")
|
||||
if self.url_base is None:
|
||||
raise ClassNotReadyException("URL base not set!")
|
||||
return self.url_base
|
||||
|
||||
|
||||
def handle_response(response):
|
||||
if response.status_code != 200 or response.status_code != 204:
|
||||
raise Exception("Response not 200 or 204!")
|
||||
else:
|
||||
return response.json()
|
||||
Reference in New Issue
Block a user