コード例 #1
0
def handle_state_change():
    """
    handle_state_change checks the state_change_queue.
    Clients put a message on this queue if one of their variables
    changed, like the temperature or hatch-open/close.
    This function listens for new messages on that queue and
    handles them by sending a message to api-clients to
    notify them of the change.
    """
    while True:
        change = state_change_queue.get()

        url = "/module/" + change.module_id
        if change.new is not None:
            url += "/add"
            change.value = api.format_module(change.value.name, change.value)
        elif change.sensor_id is not None:
            url += ("/sensor/" + change.sensor_id + "/dataitem/" +
                    change.data_item)
        else:
            url += "/dataitem/" + change.data_item

        count = api.send_request(url, change.value)
        if SPAM_DEBUG:
            print("Informed api clients of modified state", url, change.value,
                  ". Clients count:", count)
コード例 #2
0
    def __check_quit_queue(self):
        while True:
            try:
                port = self.client_stop_queue.get(block=False)
                if port is None:
                    break
                if port in self.clients:
                    name = self.clients[port].name
                    del self.clients[port]
                    print("Removed client:", port)

                    api.send_request("/module/" + name + "/delete")
                    if SPAM_DEBUG:
                        print("Informed api clients of removed module")

            except Empty:
                break
コード例 #3
0
def send_image():
    json = request.get_json(force=True)
    img = json['img']['data']['data']
    img_width = json['img']['width']
    img_height = json['img']['height']
    api_response = api.send_request(img, img_width, img_height)
    resp = make_response(jsonify(api_response), 200)
    resp.mimetype = "application/json"
    resp.headers['X-Content-Type-Options'] = 'nosniff'
    resp.headers['Content-Type'] = "application/json"
    return resp
コード例 #4
0
ファイル: publication.py プロジェクト: xie137z/pyDDP
def delete(name):
	req_body = {}
	req_body["verb"]="delete_pub"
	req_body["attributes"]={}
	req_body["attributes"]["name"]=name
	response = api.send_request(req_body)
	code = response["res_number"]
	if code==404:
		return -1
	elif code==200:
		return 0
	else:
		return -100
コード例 #5
0
ファイル: subscription.py プロジェクト: kuba-orlik/pyDDP
def newSub(pub_name):
    req_body = {}
    req_body["verb"] = "sub"
    req_body["attributes"] = {}
    new_sub_id = str(uuid.uuid4())
    req_body["attributes"]["id"] = new_sub_id
    req_body["attributes"]["pub_name"] = pub_name
    response = api.send_request(req_body)
    if response["status"] == "ok":
        sub = Subscription(pub_name, response["message"], new_sub_id)
        return sub
    else:
        raise Exception("publication does not exist")
コード例 #6
0
def newSub(pub_name):
    req_body = {}
    req_body["verb"] = "sub"
    req_body["attributes"] = {}
    new_sub_id = str(uuid.uuid4())
    req_body["attributes"]["id"] = new_sub_id
    req_body["attributes"]["pub_name"] = pub_name
    response = api.send_request(req_body)
    if response["status"] == "ok":
        sub = Subscription(pub_name, response["message"], new_sub_id)
        return sub
    else:
        raise Exception("publication does not exist")
コード例 #7
0
ファイル: publication.py プロジェクト: xie137z/pyDDP
def create(name, body_str):
	req_body = {}
	req_body["verb"]="new_pub"
	req_body["attributes"]={}
	req_body["attributes"]["name"]=name
	try:
		body_obj = json.loads(body_str)
	except:
		return -1
	req_body["attributes"]["content"]=body_obj
	response = api.send_request(req_body)
	if response["res_number"]==420:
		return -2
	else:
		return 0
コード例 #8
0
ファイル: publication.py プロジェクト: xie137z/pyDDP
def replace(name, new_content_str):
	try:
		new_content = json.loads(new_content_str)
	except:
		return -3
	req_body = {}
	req_body["verb"]="replace_pub"
	req_body["attributes"]={}
	req_body["attributes"]["pub_name"]=name
	req_body["attributes"]["new_content"]=new_content
	response = api.send_request(req_body)
	res_number = response["res_number"]
	#print(response)
	if res_number==404:
		return -1
	elif res_number==200:
		return 0
	else:
		return -100
コード例 #9
0
ファイル: publication.py プロジェクト: xie137z/pyDDP
def update(name, patch_to_apply):
	req_body = {}
	req_body["verb"]="update_pub"
	req_body["attributes"]={}
	req_body["attributes"]["pub_name"]=name
	try:
		patch_to_apply = json.loads(patch_to_apply)
	except:
		return -3
	req_body["attributes"]["changes"]=patch_to_apply
	response = api.send_request(req_body)
	res_number = response["res_number"]
	if res_number==300:
		#invalid patch:
		return -1
	elif res_number==404:
		return -2
	elif res_number==200:
		return 0
	else:
		return -100
コード例 #10
0
ファイル: app.py プロジェクト: DerrickSun/marsxxx
def translateContent(text):
    content = send_request(text)
    # return jsonify({'content': content})
    var = '.'.join(content)

    return var
コード例 #11
0
ファイル: app.py プロジェクト: DerrickSun/marsxxx
def translate():
    text = request.args.get('text')
    content = send_request(text)

    return jsonify({'content': content})