예제 #1
0
 def get_states(key=None, subkey=None):
     if subkey:
         return json.dumps(self.monitor.states[key][subkey])
     elif key:
         return json.dumps(self.monitor.states[key])
     else:
         return self.monitor.states.json
 def handle_json(self, artwork):
     '''send the complete details as json object'''
     artwork = json.dumps(artwork)
     cherrypy.response.headers['Content-Type'] = 'application/json'
     cherrypy.response.headers['Content-Length'] = len(artwork)
     if cherrypy.request.method.upper() == 'GET':
         return artwork
예제 #3
0
 def publish(self, topic, value, qos=None, retain=None):
     LOGGER.debug("publish %s to topic %s" % (value, topic))
     if qos == None:
         qos = self.config["MQTT_QOS"]
     if retain == None:
         retain = self.config["MQTT_RETAIN"]
     try:
         value = json.dumps(value)
     except:
         pass
     return self._mqttc.publish(topic, value, qos=qos, retain=retain)
예제 #4
0
    def get_json(url, params):
        '''get info from json api'''
        result = {}
        try:
            response = requests.get(url, data=json.dumps(params), timeout=20)
            if response and response.content and response.status_code == 200:
                result = json.loads(response.content.decode('utf-8', 'replace'))
                if "result" in result:
                    result = result["result"]
            else:
                LOGGER.warning("Invalid or empty reponse from server - server response: %s" %
                        (response.status_code))
        except Exception as exc:
            LOGGER.error("Server is offline or connection error... %s" % exc)

        #log_msg("%s --> %s" %(params, result))
        return result