Exemple #1
0
 def check_session_id(self, prism_session_id):
     session_params = {"session_id": prism_session_id}
     result = self.do_post(self.check_session_url, session_params)
     logger.info("[check_session_id] %s \t \n" % (result))
     if result == "":
         return False
     else:
         session_result = json.loads(result)
         # todo
     return True
Exemple #2
0
 def go_token(self, code):
     token_params = {"code": code, "grant_type": "authorization_code", "client_id": self.key, "client_secret": self.secret, "state": "1212"}
     result = WebUtil.do_post(self.token_url, self.url_info, token_params, self.get_headers())
     logger.info("[go_token] %s \t \n" % (result))
     token_result = json.loads(result)
     self.token = token_result["access_token"]
     self.session_id = token_result["session_id"]
     self.refresh_token = token_result["refresh_token"]
     if not isBlank(self.token):
         self.set_session("session_id", self.session_id)
Exemple #3
0
 def on_close(self, socket):
     logger.info("[PrismNotify] on_close")
     logger.info("[PrismNotify] real_times:%s \t retry_times:%s \t \n" % (self.real_times, self.retry_times))
     if self.real_times < self.retry_times or self.retry_times == None:
         time.sleep(self.sleep)
         self.socket = websocket.WebSocketApp(self.ws_url,
                                              on_open=self.on_open,
                                              on_message=self.message_handler.on_message,
                                              on_error=self.on_error,
                                              on_close=self.on_close)
         self.consume()
Exemple #4
0
    def do_get(url, url_info, params, header_data, is_https=False):
        url += WebUtil.build_query(params)
        logger.info("Request Type:do_get \t \n")
        logger.info("Request Url:%s \t \n" % (url))
        logger.info("Request Params:%s \t \n" % (params))
        logger.info("Request Header Message:%s \t \n" % (header_data))
        conn = None
        try:
            if is_https:
                conn = httplib.HTTPSConnection(url_info.host, 443)
            else:
                conn = httplib.HTTPConnection(url_info.host, url_info.port, 30)

            conn.request(METHOD_GET, url, headers=header_data)

            response = conn.getresponse()
            return response.read()
        except Exception, e:
            logger.error("do_get:%s \t \n" % (e))
Exemple #5
0
    def do_post(url, url_info, params, header_data, is_https=False):
        logger.info("Request Type:do_post \t \n")
        logger.info("Request Url:%s \t \n" % (url))
        logger.info("Request Params:%s \t \n" % (params))
        logger.info("Request Header Message:%s \t \n" % (header_data))

        conn = None
        try:
            params = urllib.urlencode(params)
            if is_https:
                conn = httplib.HTTPSConnection(url_info.host, 443)
            else:
                conn = httplib.HTTPConnection(url_info.host, url_info.port, 30)

            conn.request(METHOD_POST, url, body=params, headers=header_data)
            response = conn.getresponse()
            return response.read()
        except Exception, e:
            logger.error("do_post:%s \t \n" % (e))
Exemple #6
0
    def do_get(url, url_info, params, header_data, is_https=False):
        url += WebUtil.build_query(params)
        logger.info("Request Type:do_get \t \n")
        logger.info("Request Url:%s \t \n" % (url))
        logger.info("Request Params:%s \t \n" % (params))
        logger.info("Request Header Message:%s \t \n" % (header_data))
        conn = None
        try:
            if is_https:
                conn = httplib.HTTPSConnection(url_info.host, 443)
            else:
                conn = httplib.HTTPConnection(url_info.host, url_info.port, 30)

            conn.request(METHOD_GET, url, headers=header_data)

            response = conn.getresponse()
            return response.read()
        except Exception, e:
            logger.error("do_get:%s \t \n" % (e))
Exemple #7
0
    def do_post(url, url_info, params, header_data, is_https=False):
        logger.info("Request Type:do_post \t \n")
        logger.info("Request Url:%s \t \n" % (url))
        logger.info("Request Params:%s \t \n" % (params))
        logger.info("Request Header Message:%s \t \n" % (header_data))

        conn = None
        try:
            params = urllib.urlencode(params)
            if is_https:
                conn = httplib.HTTPSConnection(url_info.host, 443)
            else:
                conn = httplib.HTTPConnection(url_info.host, url_info.port, 30)

            conn.request(METHOD_POST, url, body=params, headers=header_data)
            response = conn.getresponse()
            return response.read()
        except Exception, e:
            logger.error("do_post:%s \t \n" % (e))
Exemple #8
0
 def consume(self):
     self.real_times += 1
     logger.info("[PrismNotify] consume")
     self.data = self.assemble_consume_date()
     self.socket.run_forever()
Exemple #9
0
 def publish(self, routing_key, message):
     logger.info("[PrismNotify] publish")
     self.data = self.assemble_publish_data(routing_key, message)
     self.socket.run_forever()
Exemple #10
0
 def on_error(self, socket, error):
     logger.info("[PrismNotify] on_error,error is %s" % (error))
Exemple #11
0
 def on_open(self, ws):
     logger.info("[PrismNotify] on_open %s " % (self.data))
     ws.send(self.data)