示例#1
0
def chinaUnicomAPI(phone_attr):
    """
    :param phone_attr: dict(phone=XX, province=XX,city=XX, company=XX, password=XX)
    :param password: 全为数字的字符串(长度不少于6位)
    :return:
    """
    # makeDirs()
    check_param = checkAttr(phone_attr)
    if check_param != True:
        return check_param  # 返回参数错误

    spider = ChinaUnicom(phone_attr)
    login = spider.loginSys()
    if login['code'] != 2000:
        return returnResult(login['code'], data={})  # 返回登陆错误信息
    else:
        spider.getUserInfo()
        spider.getCallInfo()
        # spider.saveItems()
        # clawLog(phone_attr, log)
        data = dict(t_operator_user=spider.user_items,
                    t_operator_call=spider.call_items,
                    t_operator_note=list())
        # 返回爬取结果
        return returnResult(2000, data=data)
示例#2
0
def getPhoneAttr(phone_num):
    """ 调用百度api获得手机的归属地
    :param phone_num: 手机号
    :return:统一接口返回
    example:
        >>searchPhoneInfo('15802028888')
        正常返回key data对应的元素例子
        {'phone':'13267175437', 'province':'广东', 'city':'深圳', 'company':1}
        company值:中国联通1; 中国移动2; 中国电信3, 其他4
    """
    phone_status = 6855 if str(phone_num)[0] == '0' else 6004
    url = 'https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php'
    params = {'query': phone_num, 'resource_id': phone_status}
    options = {'method': 'get', 'url': url, 'params': params}

    response = basicRequest(options)
    if response:
        try:
            company_type = 4
            item = json.loads(response.text)['data'][0]
            if item['type'] in _company_convert.keys():
                company_type = _company_convert[item['type']]
            data = {
                'phone': phone_num,
                'province': item['prov'],
                'city': item['city'],
                'company': company_type
            }
            return returnResult(code=2000, data=data, desc=u'查询成功')
        except (KeyError, IndexError):
            return returnResult(code=4500, data={})
        except (ValueError, Exception):
            return returnResult(code=4100, data={})
    else:
        return returnResult(code=4000, data={})
示例#3
0
def creditPersonAPI(name, password, auth_code):
    """
    :param name: 用户名
    :param password: 登录密码
    :param auth_code: 身份验证码
    :return:
    """
    person = CreditReport(name, password, auth_code)
    result = person.visitSys()
    if result['result'] == 2000:
        data = dict(file_name=result['file_name'])
        return returnResult(code=2000, data=data)
    else:
        return returnResult(code=result['result'], data={})
示例#4
0
def checkAttr(phone_attr):
    _key = ('phone', 'province', 'city', 'company', 'password')
    if not isinstance(phone_attr, dict) or set(phone_attr.keys()) != set(_key):
        return returnResult(4400, data={})
    else:  # 参数正确返回True
        return True