Пример #1
0
 def get(self):
     """
     http get handler
     """
     try:
         SUtils.init()
         return_val = {
             'data': {},
             'status': ConstantVar.st_other,
             'msg': '',
         }
         logger.info("\n\nget %s", self.request.body)
         param_date = self.get_argument("date", '')
         param_time = self.get_argument("t", '')
         param_nonce = self.get_argument("n", '')
         param_sign = self.get_argument('s', '')
         be_ok = self.validate_parameter(param_date, param_time,
                                         param_nonce, param_sign)
         if not be_ok:
             return_val['msg'] = ConstantVar.status_msg[
                 ConstantVar.st_param_error]
             return_val['status'] = ConstantVar.st_param_error
             result_str = ujson.encode(return_val, ensure_ascii=False)
             self.write(result_str)
             return
         try:
             be, desc = SUtils.check_sign(param_time, param_nonce,
                                          param_sign)
             if not be:
                 return_val['msg'] = ConstantVar.status_msg[
                     ConstantVar.st_access_deny]
                 return_val['status'] = ConstantVar.st_access_deny
                 result_str = ujson.encode(return_val, ensure_ascii=False)
                 self.write(result_str)
                 return
         except Exception as e:
             logger.error(e)
             return_val['msg'] = ConstantVar.status_msg[
                 ConstantVar.st_other]
             return_val['status'] = ConstantVar.st_other
             result_str = ujson.encode(return_val, ensure_ascii=False)
             self.write(result_str)
             return
         result = self.deal(param_date)
         return_val['data'] = result
         return_val['status'] = ConstantVar.st_success
         result_str = ujson.encode(return_val, ensure_ascii=False)
         # logger.info("result_str:%s", result_str)
         self.write(result_str)
     except Exception, e:
         logger.error(e)
         return_val['msg'] = ConstantVar.status_msg[ConstantVar.st_other]
         return_val['status'] = ConstantVar.st_other
         result_str = ujson.encode(return_val, ensure_ascii=False)
         self.write(result_str)
    def post(self):
        """
        : http post handler:
        """
        try:
            SUtils.init()
            return_val = {
                'data': {},
                'status': ConstantVar.st_other,
                'msg': '',
            }
            logger.info("\n\npost: %s", self.request.body)
            param_time = self.get_argument('t', '')
            param_nonce = self.get_argument('n', '')
            param_sign = self.get_argument('s', '')
            para_start_date = self.get_argument('start_date', '')
            para_end_date = self.get_argument('end_date', '')
            cids_list = self.get_argument('cids', '')
            crawler_channel = self.get_argument('crawler_channel', '')
            telecom = self.get_argument('telecom', '')
            province = self.get_argument('province', '')
            be_ok = self.validate_parameter(para_start_date, para_end_date,
                                            param_time, cids_list, param_nonce,
                                            param_sign)
            if not be_ok:
                return_val['msg'] = ConstantVar.status_msg[
                    ConstantVar.st_param_error]
                return_val['status'] = ConstantVar.st_param_error
                result_str = ujson.encode(return_val, ensure_ascii=False)
                self.write(result_str)
                return

            try:
                be, desc = SUtils.check_sign(param_time, param_nonce,
                                             param_sign)
                if not be:
                    return_val['msg'] = ConstantVar.status_msg[
                        ConstantVar.st_access_deny]
                    return_val['status'] = ConstantVar.st_access_deny
                    result_str = ujson.encode(return_val, ensure_ascii=False)
                    self.write(result_str)
                    return
            except Exception as e:
                logger.error(e)
                return_val['status'] = ConstantVar.st_other
                return_val['msg'] = ConstantVar.status_msg[
                    ConstantVar.st_other]
                result_str = ujson.encode(return_val, ensure_ascii=False)
                self.write(result_str)
                return

            if cids_list:
                cids_list = eval(cids_list)

            # deal
            result = self.deal(para_start_date, para_end_date, cids_list,
                               telecom, province, crawler_channel)
            # json obj 2 str
            return_val['data'] = result
            return_val['status'] = ConstantVar.st_success
            result_str = ujson.encode(return_val, ensure_ascii=False)
            self.write(result_str)
        except Exception as e:
            logger.error(e)
            return_val['status'] = ConstantVar.st_other
            return_val['msg'] = ConstantVar.status_msg[ConstantVar.st_other]
            result_str = ujson.encode(return_val, ensure_ascii=False)
            self.write(result_str)