def get(self, uid): """get all temp-io devices of specific user""" if self.req_user and self.req_user['myself'] is True: wio = Wio(self.req_token) try: thing_list = yield wio.get_all_thing() except Exception as e: gen_log.error(e) raise HTTPError(400, "Get temp is failure, {}".format(e.message)) if thing_list is None: self.set_status(200) self.finish({"temps": []}) return docs = yield self.db_temp.get_all_temp_by_uid(uid) temp_list = [jsonify(doc) for doc in docs] for temp in temp_list[:]: # FIXME, need more efficiency for thing in thing_list: if thing['id'] == temp['id']: temp['online'] = thing['online'] self.finish({"temps": temp_list}) else: docs = yield self.db_temp.get_all_temp_by_uid(uid) temp_list = [] for doc in docs: if doc['private'] is False: temp_list.append(jsonify(doc)) self.finish({"temps": temp_list})
def get(self, uid, tid): if self.req_user and self.req_user['myself'] is True: data = jsonify(self.temp) wio = Wio(self.req_token) try: thing_list = yield wio.get_all_thing() except Exception as e: gen_log.error(e) raise HTTPError( 400, "Get thing is failure from built-in Wio server, {}".format( str(e))) for thing in thing_list: if thing["id"] == data["id"]: data["online"] = thing["online"] self.finish(data) else: if self.temp['private'] is True: raise HTTPError(400, "The device is private") data = jsonify(self.temp) # value = {} # TODO, filter output value # for key in ['temperature', 'temperature_f', 'temperature_updated_at', 'updated_at', 'created_at']: # value[key] = data[key] # self.finish(value) self.finish(data)
def get(self, uid): wio = Wio(self.current_user['token']) try: thing_list = yield wio.get_all_thing() except Exception as e: gen_log.error(e) self.set_status(400) self.finish({"error": "Get temp is failure, {}".format(e.message)}) return if thing_list is None: self.set_status(400) self.finish({"temps": []}) return docs = yield self.db_temp.get_all_temp_by_uid(uid) temp_list = [jsonify(doc) for doc in docs] for temp in temp_list[:]: # FIXME, need more efficiency for thing in thing_list: if thing['id'] == temp['id']: temp['online'] = thing['online'] self.finish({"temps": temp_list})
def get(self, uid, tid): # TODO: (ten) authenticated uid is correct? result = yield self.db_temp.get_temp(tid) if result is None: gen_log.error("Not this temp") self.set_status(400) self.finish({"error": "Not this temp"}) return wio = Wio(self.current_user['token']) try: thing_list = yield wio.get_all_thing() except Exception as e: gen_log.error(e) self.set_status(400) self.finish({"error": "Get thing is failure on Wio, {}".format(e.message)}) return data = jsonify(result) for thing in thing_list: if thing["id"] == data["id"]: data["online"] = thing["online"] self.finish(data)