当前位置: 首页>>代码示例>>Python>>正文


Python QueryHelper.get_ajt_whitelist_by_mobile方法代码示例

本文整理汇总了Python中helpers.queryhelper.QueryHelper.get_ajt_whitelist_by_mobile方法的典型用法代码示例。如果您正苦于以下问题:Python QueryHelper.get_ajt_whitelist_by_mobile方法的具体用法?Python QueryHelper.get_ajt_whitelist_by_mobile怎么用?Python QueryHelper.get_ajt_whitelist_by_mobile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在helpers.queryhelper.QueryHelper的用法示例。


在下文中一共展示了QueryHelper.get_ajt_whitelist_by_mobile方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_ajt_whitelist_by_mobile [as 别名]
 def post(self):
     """Add a whitelist.
     """
     status = ErrorCode.SUCCESS
     try:
         data = json_decode(self.request.body)
         mobile = data.get('mobile')
         ajt = QueryHelper.get_ajt_whitelist_by_mobile(mobile, self.db)
         if ajt:
             status = ErrorCode.AJT_ORDERED
             message = ErrorCode.ERROR_MESSAGE[status] % mobile
             self.write_ret(status, 
                            message=message)
         else:
             self.db.execute("INSERT INTO T_AJT_WHITELIST(mobile, timestamp)"
                             "  VALUES (%s, %s)"
                             "  ON DUPLICATE KEY"
                             "  UPDATE mobile = VALUES(mobile),"
                             "         timestamp = VALUES(timestamp)", 
                             mobile, int(time.time()))
             self.write_ret(status)
     except Exception as e:
         logging.exception("[ADMIN] Add whitelist failed. Terminal mobile: %s.", 
                           mobile)
         self.render('errors/error.html', 
                     message=ErrorCode.FAILED)
开发者ID:jcsy521,项目名称:ydws,代码行数:28,代码来源:whitelist_ajt.py

示例2: handle_locationdesc

# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_ajt_whitelist_by_mobile [as 别名]
def handle_locationdesc(info, address, connection, channel, exchange, gw_binding, db, redis):
    """
    S10
    locationdesc packet

    0: success, then return locationdesc to terminal and record new terminal's address
    1: invalid SessionID 
    """
    try:
        head = info.head
        body = info.body
        dev_id = head.dev_id
        if len(body) == 6:
            body.append(20) 
            logging.info("[GW] old version is compatible, append locate_error")

        resend_key, resend_flag = get_resend_flag(redis, dev_id, head.timestamp, head.command) 

        go_ahead = False 
        args = DotDict(success=GATEWAY.RESPONSE_STATUS.SUCCESS,
                       locationdesc="",
                       ew="E",
                       lon=0.0,
                       ns="N",
                       lat=0.0)
        sessionID = QueryHelper.get_terminal_sessionID(dev_id, redis)
        if sessionID != head.sessionID:
            args.success = GATEWAY.RESPONSE_STATUS.INVALID_SESSIONID
            logging.error("[GW] Invalid sessionID, terminal: %s", head.dev_id)
        else:
            if resend_flag:
                logging.warn("[GW] Recv resend packet, head: %s, body: %s and drop it!",
                             info.head, info.body)
            else:
                go_ahead = True


        #NOTE: Check ydcw or ajt 
        ajt = QueryHelper.get_ajt_whitelist_by_mobile(head.dev_id, db) 
        if ajt: 
            url_out = ConfHelper.UWEB_CONF.ajt_url_out 
        else: 
            url_out = ConfHelper.UWEB_CONF.url_out

        if go_ahead:
            redis.setvalue(resend_key, True, GATEWAY.RESEND_EXPIRY)
            ldp = LocationDescParser(body, head)
            location = ldp.ret
            logging.info("[GW] T10 packet parsered:%s", location)
            if not  location.has_key('gps_time'):
                location['gps_time'] = int(time.time())
                logging.info("[GW] what's up? location:%s hasn't gps_time.", location)
            location['t'] = EVENTER.INFO_TYPE.POSITION
            if location['valid'] != GATEWAY.LOCATION_STATUS.SUCCESS:
                cellid = True
            else:
                cellid = False
            location = lbmphelper.handle_location(location, redis, cellid=cellid, db=db)
            location.name = location.get('name') if location.get('name') else ""
            location.name = safe_unicode(location.name)
            user = QueryHelper.get_user_by_tid(head.dev_id, db)
            tname = QueryHelper.get_alias_by_tid(head.dev_id, redis, db)
            dw_method = u'GPS' if not cellid else u'基站'
            if location.cLat and location.cLon:
                if user:
                    current_time = get_terminal_time(int(time.time()))
                    sms = SMSCode.SMS_DW_SUCCESS % (tname, dw_method,
                                                    location.name, 
                                                    safe_unicode(current_time)) 
                    url = url_out + '/wapimg?clon=' +\
                          str(location.cLon/3600000.0) + '&clat=' + str(location.cLat/3600000.0)
                    tiny_id = URLHelper.get_tinyid(url)
                    if tiny_id:
                        base_url = url_out + UWebHelper.URLS.TINYURL
                        tiny_url = base_url + '/' + tiny_id
                        logging.info("[GW] get tiny url successfully. tiny_url:%s", tiny_url)
                        redis.setvalue(tiny_id, url, time=EVENTER.TINYURL_EXPIRY)
                        sms += u"点击 " + tiny_url + u" 查看定位器位置。" 
                    else:
                        logging.info("[GW] get tiny url failed.")
                    SMSHelper.send(user.owner_mobile, sms)
            else:
                if user:
                    sms = SMSCode.SMS_DW_FAILED % (tname, dw_method)
                    SMSHelper.send(user.owner_mobile, sms)
            if not (location.lat and location.lon):
                args.success = GATEWAY.RESPONSE_STATUS.CELLID_FAILED
            else:
                insert_location(location, db, redis)

        lc = LocationDescRespComposer(args)
        request = DotDict(packet=lc.buf,
                          address=address,
                          dev_id=dev_id)
        update_terminal_status(redis, head.dev_id, address)
        append_gw_request(request, connection, channel, exchange, gw_binding)
    except:
        logging.exception("[GW] Handle locationdesc exception.")
        GWException().notify()
开发者ID:jcsy521,项目名称:ydws,代码行数:101,代码来源:locationdesc.py

示例3: handle_old_login

# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_ajt_whitelist_by_mobile [as 别名]

#.........这里部分代码省略.........
                             t_info['dev_id'], t_info['u_msisdn'],
                             terminal.service_status)
                delete_terminal_new(t_info['dev_id'], db, redis, del_user=False)
                exist = db.get("SELECT tid, owner_mobile, service_status FROM T_TERMINAL_INFO"
                               "  WHERE mobile = %s LIMIT 1",
                               t_info['t_msisdn'])
                if exist:
                    # cannot send unbind packet to dev_id
                    t_status = None
                    logging.info("[GW] Delete old tmobile bind relation. tid: %s, mobile: %s",
                                 exist.tid, t_info['t_msisdn'])
                    delete_terminal_new(exist.tid, db, redis, del_user=False)
                    if exist.service_status == UWEB.SERVICE_STATUS.TO_BE_UNBIND:
                        logging.info("[GW] Terminal: %s of %s is to_be_unbind, delete it.",
                                     exist.tid, t_info['t_msisdn'])
                    elif exist.owner_mobile != t_info['u_msisdn']:
                        sms = SMSCode.SMS_DELETE_TERMINAL % t_info['t_msisdn']
                        SMSHelper.send(exist.owner_mobile, sms)
                terminal = None
            else:
                args.success = GATEWAY.LOGIN_STATUS.ILLEGAL_SIM
                sms = SMSCode.SMS_TID_EXIST % t_info['dev_id']
                SMSHelper.send(t_info['u_msisdn'], sms)
                lc = LoginRespComposer(args)
                request = DotDict(packet=lc.buf,
                                  address=address,
                                  dev_id=t_info["dev_id"])
                append_gw_request(request, connection, channel, exchange, gw_binding)
                logging.error("[GW] Login failed! Terminal: %s already bound by %s, new mobile: %s",
                              t_info['dev_id'], terminal.mobile, t_info['t_msisdn'])
                return

    #NOTE: Check ydcw or ajt 
    ajt = QueryHelper.get_ajt_whitelist_by_mobile(t_info['t_msisdn'], db) 
    if ajt: 
        url_out = ConfHelper.UWEB_CONF.ajt_url_out 
    else: 
        url_out = ConfHelper.UWEB_CONF.url_out 
    logging.info("[GW] Terminal: %s, login url is: %s", t_info['t_msisdn'], url_out)

    if t_info['psd']:
        flag = 0
        # check terminal exist or not when HK
        if not terminal:
            args.success = GATEWAY.LOGIN_STATUS.UNREGISTER
            sms = SMSCode.SMS_TID_NOT_EXIST
            SMSHelper.send(t_info['u_msisdn'], sms)
            lc = LoginRespComposer(args)
            request = DotDict(packet=lc.buf,
                              address=address,
                              dev_id=t_info["dev_id"])
            append_gw_request(request, connection, channel, exchange, gw_binding)
            logging.error("[GW] Login failed! Terminal %s execute HK, but tid is not exist",
                          t_info['dev_id'])
            return
        # HK, change terminal mobile or owner mobile
        logging.info("[GW] Checking password. Terminal: %s",
                     t_info['dev_id'])
        owner = db.get("SELECT id FROM T_USER"
                       "  WHERE mobile = %s"
                       "    AND password = password(%s)",
                       terminal.owner_mobile, t_info['psd'])
        if not owner:
            # psd wrong
            sms = SMSCode.SMS_PSD_WRONG
            args.success = GATEWAY.LOGIN_STATUS.PSD_WRONG
开发者ID:jcsy521,项目名称:ydws,代码行数:70,代码来源:login.py

示例4: handle_new_login

# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_ajt_whitelist_by_mobile [as 别名]

#.........这里部分代码省略.........
        begintime = datetime.datetime.now() 
        endtime = begintime + relativedelta(years=1)

        # 1. check data validation
        logging.info("[GW] Checking terminal mobile: %s and owner mobile: %s, Terminal: %s",
                     t_info['t_msisdn'], t_info['u_msisdn'], t_info['dev_id'])
        if not (check_phone(t_info['u_msisdn']) and check_phone(t_info['t_msisdn'])):
            args.success = GATEWAY.LOGIN_STATUS.ILLEGAL_SIM
            lc = LoginRespComposer(args)
            request = DotDict(packet=lc.buf,
                              address=address,
                              dev_id=t_info['dev_id'])
            if t_info['u_msisdn']:
                # send JH failed caution to owner
                sms = SMSCode.SMS_JH_FAILED
                SMSHelper.send(t_info['u_msisdn'], sms)
            logging.error("[GW] Login failed! Invalid terminal mobile: %s or owner_mobile: %s, tid: %s",
                          t_info['t_msisdn'], t_info['u_msisdn'], t_info['dev_id'])

            append_gw_request(request, connection, channel, exchange, gw_binding)
        # 2. delete to_be_unbind terminal
        if terminal and terminal.service_status == UWEB.SERVICE_STATUS.TO_BE_UNBIND:
            logging.info("[GW] Delete terminal which is to_be_unbind. tid: %s, mobile: %s", 
                         terminal['tid'], terminal['mobile'])
            delete_terminal_new(terminal['tid'], db, redis)
            terminal = None

        # 3. add user info
        exist = db.get("SELECT id FROM T_USER"
                       "  WHERE mobile = %s",
                       t_info['u_msisdn'])

        #NOTE: Check ydcw or ajt
        ajt = QueryHelper.get_ajt_whitelist_by_mobile(t_info['t_msisdn'], db)
        if ajt:
           url_out = ConfHelper.UWEB_CONF.ajt_url_out
        else:
           url_out = ConfHelper.UWEB_CONF.url_out
        logging.info("[GW] Login url is: %s, tid: %s, mobile: %s ", 
                     url_out, t_info['dev_id'], t_info['t_msisdn'])

        if exist:
            logging.info("[GW] Owner already existed. tid: %s, mobile: %s", 
                         t_info['dev_id'], t_info['t_msisdn'])
            sms = SMSCode.SMS_USER_ADD_TERMINAL % (t_info['t_msisdn'],
                                                   url_out)
        else:
            # get a new psd for new user
            logging.info("[GW] Create new owner started. tid: %s, mobile: %s", t_info['dev_id'], t_info['t_msisdn'])
            psd = get_psd()
            user_info = dict(umobile=t_info['u_msisdn'],
                             password=psd, 
                             uname=t_info['u_msisdn'])
            add_user(user_info, db, redis)
            sms = SMSCode.SMS_JH_SUCCESS % (t_info['t_msisdn'],
                                            url_out,
                                            t_info['u_msisdn'],
                                            psd)

        # 4. JH existed tmobile
        is_refurbishment = False
        if terminal:
            if (terminal['tid'] == t_info['dev_id']) and \
               (terminal['imsi'] == t_info['imsi']) and \
               (terminal['owner_mobile'] == t_info['u_msisdn']):
                # 4.1 SCN: Refurbishment, the terminal-info has existed in platform. JH it again.
开发者ID:jcsy521,项目名称:ydws,代码行数:70,代码来源:login.py

示例5: post

# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_ajt_whitelist_by_mobile [as 别名]
    def post(self):
        """Read excel.
        """
        try:
            upload_file = self.request.files['upload_file'][0]
            logging.info("[UWEB] batch import.")
        except Exception as e:
            logging.info("[ADMIN] Invalid data format, Exception: %s",
                e.args) 
            status = ErrorCode.ILLEGAL_DATA_FORMAT
            self.write_ret(status)
            return

        try:
            status = ErrorCode.SUCCESS
            original_fname = upload_file['filename']
            extension = os.path.splitext(original_fname)[1]
            if extension not in ['.xlsx', '.xls']:
                status = ErrorCode.ILLEGAL_EXCEL_FILE
                self.write_ret(status)
                return

            # write into tmp file
            fname = ''.join(random.choice(string.ascii_lowercase + string.digits) for x in range(6))
            final_filename= fname + extension
            file_path = final_filename
            output_file = open(file_path, 'w')
            output_file.write(upload_file['body'])
            output_file.close()

            res = []
            # read from tmp file
            wb = xlrd.open_workbook(file_path)
            for sheet in wb.sheets():
                #NOTE: first line is title, and it should be ignored
                for j in range(1, sheet.nrows): 
                    row = sheet.row_values(j)
                    mobile = unicode(row[0])
                    mobile = mobile[0:11]

                    r = DotDict(mobile=mobile,
                                status=ErrorCode.SUCCESS)   

                    if not check_phone(mobile): 
                        r.status = UWEB.TERMINAL_STATUS.INVALID 
                        res.append(r) 
                        continue 

                    ajt = QueryHelper.get_ajt_whitelist_by_mobile(mobile, self.db)
                    if ajt:
                        r.status = UWEB.TERMINAL_STATUS.EXISTED
                    else:
                        pass
                    res.append(r)
            # remove tmp file
            os.remove(file_path)
            self.render("whitelist/fileUpload.html",
                        status=ErrorCode.SUCCESS,
                        res=res)
                  
        except Exception as e:
            logging.exception("[UWEB] Batch import failed. Exception: %s",
                e.args)
            status = ErrorCode.ILLEGAL_FILE
            self.render("whitelist/fileUpload.html",
                        status=status,
                        message=ErrorCode.ERROR_MESSAGE[status])
开发者ID:jcsy521,项目名称:ydws,代码行数:69,代码来源:whitelist.py


注:本文中的helpers.queryhelper.QueryHelper.get_ajt_whitelist_by_mobile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。