def _get_division(tmzjhm: str) -> None:
     try:
         return gb2260.get(tmzjhm[:6])
     except ValueError:
         years = [year for year in gb2260.data.data if year is not None]
         years.sort(key=truncate_int, reverse=True)
         for year in years:
             try:
                 return gb2260.get(tmzjhm[:6], year)
             except ValueError:
                 continue
         return None
Beispiel #2
0
def decode_0x0100(bytes):
    body_index = get_message_body_index(bytes)
    body_length = get_message_body_length(bytes)
    province_id = Covert.bytes_2_number(bytes, body_index + 0, 2)
    city_id = Covert.bytes_2_number(bytes, body_index + 2, 2)

    province_id_str = str(province_id)
    format_province_id_str = ''.join(['0' for i in range(2 - len(province_id_str))]) + province_id_str
    city_id_str = str(city_id)
    format_city_id_str = ''.join(['0' for i in range(4 - len(city_id_str))]) + city_id_str

    division = gb2260.get(int(format_province_id_str + format_city_id_str))
    print('code', int(format_province_id_str + format_city_id_str))
    print('division.province', type(division.province), division.province, division.province.__str__())
    print('division.name', type(division.name))
    return {**decode_header(bytes), **{
        '含义': '终端注册',
        '消息体': Covert.bytes_2_hex_string(bytes, body_index + 0, body_length),
        '省域ID': '{0}[{1}]'.format(format_province_id_str, division.province.__str__()),
        '市县域ID': city_id_str + '[' + division.name + ']',
        '制造商ID': Covert.bytes_2_hex_string(bytes, body_index + 4, 5),
        '终端型号': Covert.bytes_2_hex_string(bytes, body_index + 9, 8),
        '终端ID': Covert.bytes_2_hex_string(bytes, body_index + 17, 7),
        '车牌颜色': Covert.bytes_2_hex_string(bytes, body_index + 24, 1) + '[' + str(LicensePateColor(Covert.bytes_2_number(bytes, body_index + 24, 1))) + ']',
        '车牌': Covert.bytes_2_hex_string(bytes, body_index + 25, body_length - 25) + '[' + bytes.fromhex(Covert.bytes_2_hex_string(bytes, body_index + 25, body_length - 25)).decode('GBK') + ']',
    }}
Beispiel #3
0
def test_division(code, stack_name, is_province, is_prefecture, is_county):
    division = get(code)
    assert division.code == code
    assert division.is_province == is_province
    assert division.is_prefecture == is_prefecture
    assert division.is_county == is_county
    assert '/'.join(x.name for x in division.stack()) == stack_name
Beispiel #4
0
def test_division(code, stack_name, is_province, is_prefecture, is_county):
    division = get(code)
    assert division.code == code
    assert division.is_province == is_province
    assert division.is_prefecture == is_prefecture
    assert division.is_county == is_county
    assert '/'.join(x.name for x in division.stack()) == stack_name
Beispiel #5
0
def current_location(current_district):
    div_result = []
    division = gb2260.get(current_district)
    for current in division.stack():
        temp = str(u'{0}'.format(current.name))
        div_result.append(temp)

    return ("-".join(str(i) for i in div_result))  # use "-" to split str
Beispiel #6
0
def test_representation_python2(code, year, repr_result, unicode_result):
    division = get(code, year)
    assert repr(division) == repr_result
    assert str(division) == unicode_result.encode('utf-8')
    assert str(division) == unicode_result
    assert isinstance(repr(division), str)
    assert isinstance(str(division), str)
    assert isinstance(str(division), str)
Beispiel #7
0
def test_representation_python2(code, year, repr_result, unicode_result):
    division = get(code, year)
    assert repr(division) == repr_result
    assert str(division) == unicode_result.encode('utf-8')
    assert unicode(division) == unicode_result
    assert isinstance(repr(division), str)
    assert isinstance(str(division), str)
    assert isinstance(unicode(division), unicode)
def place(num):
    '''接收的是完整的身份证号'''
    global cities
    city=[]
    try:
        division=gb2260.get(num[0:6])
        city.append(division.name)
    except:
        print('判断城市错误'+num)
    finally:
        cities=Counter(city)
        print('\n城市统计完成')
Beispiel #9
0
def cl_build(current_district):
    """ use gb2260 to build a CurrentLocation """
    div_result = []
    try:
        division = gb2260.get(current_district)
        for current in division.stack():
            temp = str(u"{0}".format(current.name))
            div_result.append(temp)
            # use "-" to split str
        return "-".join(str(i) for i in div_result)
    except:
        return None
Beispiel #10
0
def test_history_data():
    get(522401, year=2010) == Division(522401, '毕节市', 2010)

    with raises(ValueError) as error:
        get(522401)
    assert error.value.args[0] == '522401 is not valid division code'

    with raises(ValueError) as error:
        get(110101, 2000)
    assert error.value.args[0].startswith('year must be in')
Beispiel #11
0
def test_history_data():
    get(522401, year=2010) == Division(522401, u'毕节市', 2010)

    with raises(ValueError) as error:
        get(522401)
    assert error.value.args[0] == '522401 is not valid division code'

    with raises(ValueError) as error:
        get(110101, 2000)
    assert error.value.args[0].startswith('year must be in')
Beispiel #12
0
def test_comparable():
    assert get(110101) == Division(110101, '东城区')
    assert get(110101) != Division(110000, '北京市')
    assert get(110101, year=2006) != Division(110101, '东城区')
Beispiel #13
0
def main():

    if len(sys.argv) == 1:  #对比我喜欢的
        print UseStyle('***单用户top100分析***', fore='red')
        print '输入你的昵称:'
        myname = raw_input()
        nameJson = UserSearch(myname)
        d = json.loads(nameJson)
        try:
            myname = d['result']['userprofiles'][0]['nickname']
        except:
            print '查无此人'
        myid = d['result']['userprofiles'][0]['userId']
        gender = d['result']['userprofiles'][0]['gender']
        birthday = d['result']['userprofiles'][0]['birthday']
        city = d['result']['userprofiles'][0]['city']
        province = d['result']['userprofiles'][0]['province']
        if birthday < 0:
            birthday = 'unknown'
        else:
            x = time.localtime(float(birthday / 1000))
            birthday = time.strftime('%Y-%m-%d', x)
        try:
            province = gb2260.get(province).name
        except:
            province = 'unknown'
        try:
            city = gb2260.get(city).name
        except:
            city = 'unknown'
        if gender == 1:
            gender = 'male'
        elif gender == 2:
            gender = 'female'
        else:
            gender = 'unknown'
        people = People(myname, myid, gender, birthday, province, city)
        print '你的用户名和ID是否为%s,%s:任意键继续,Q退出' % (myname, myid)
        wait = raw_input()
        if wait == 'q' or wait == 'Q':
            exit()
        print '开始分析...'
        SingleListAnlyasis(people)

    else:
        if sys.argv[1].startswith('--'):
            option = sys.argv[1][2:]
            if (option == 'help'):
                print
                print '****************碰撞一下彼此的歌单****************'
                print
                print '*******************操作指南*********************'
                print
                print UseStyle('1. python compare.py', fore='cyan')
                print
                print UseStyle(
                    '3. python compare.py -i #i for input your name',
                    fore='cyan')
                print
                print UseStyle('4. python compare.py -ai #a for all songlist',
                               fore='cyan')
                print
                print UseStyle('5. python compare.py -ti #t for top',
                               fore='cyan')
                print

        elif sys.argv[1].startswith('-'):
            option = sys.argv[1][1:]
            if (option == 'g'):
                pass
            elif (option == 'i'):

                myid, uid = UsernameInput()

                iplaylist = GetAllListId(myid)[0]
                uplaylist = GetAllListId(uid)[0]

                compare(iplaylist, uplaylist)
            elif (option == 'ai' or option == "ia"):

                myid, uid = UsernameInput()

                iplaylist = GetAllListId(myid)
                uplaylist = GetAllListId(uid)

                CompareAll(iplaylist, uplaylist)
            elif (option == 'ti' or option == "it"):

                myid, uid = UsernameInput()

                myWeekList = GetTopLastWk(myid)
                myAllList = GetTopAllTime(myid)
                uWeekList = GetTopLastWk(uid)
                uAllList = GetTopAllTime(uid)

                CompareTopWeekly(myWeekList, uWeekList)
                CompareTopAllTime(myAllList, uAllList)
Beispiel #14
0
after = []
citys = []

print(wb.sheetnames)  #读取所有的sheet名称,保存为列表

#获得所有的身份证号
for row in ws.rows:
    mySheet.append(row[3].value)

#提取身份证号前四位(城市)
for one in mySheet:
    after.append(one[0:4])

for num in after:
    try:
        division = gb2260.get(num + '00')
        citys.append(division.name)
    except:
        citys.append('滨州市')  #就你滨州事儿多
    finally:
        #将城市人数保存到字典place里
        place = Counter(citys)
print(place)

#开始尝试可视化
from pyecharts import options as opts
from pyecharts.charts import Bar
from pyecharts.charts import Pie


#试图排序的函数
Beispiel #15
0
def test_comparable():
    assert get(110101) == Division(110101, u'东城区')
    assert get(110101) != Division(110000, u'北京市')
    assert get(110101, year=2006) != Division(110101, u'东城区')
Beispiel #16
0
def test_representation_python3(code, year, repr_result, unicode_result):
    division = get(code, year)
    assert repr(division) == repr_result
    assert str(division) == unicode_result
    assert isinstance(repr(division), str)
    assert isinstance(str(division), str)
Beispiel #17
0
def UsernameInput():
    try:
        print '你的昵称:'
        myname = raw_input()
        nameJson = UserSearch(myname)
        d = json.loads(nameJson)
        try:
            myname = d['result']['userprofiles'][0]['nickname']
        except:
            print '查无此人'
        myid = d['result']['userprofiles'][0]['userId']
        gender = d['result']['userprofiles'][0]['gender']
        birthday = d['result']['userprofiles'][0]['birthday']
        city = d['result']['userprofiles'][0]['city']
        province = d['result']['userprofiles'][0]['province']
        if birthday < 0:
            birthday = 'unknown'
        else:
            x = time.localtime(float(birthday / 1000))
            birthday = time.strftime('%Y-%m-%d', x)
        try:
            province = gb2260.get(province).name
        except:
            province = 'unknown'
        try:
            city = gb2260.get(city).name
        except:
            city = 'unknown'
        if gender == 1:
            gender = 'male'
        elif gender == 2:
            gender = 'female'
        else:
            gender = 'unknown'
        print '你的用户名和ID是否为%s,%s:任意键继续,Q退出' % (myname, myid)
        wait = raw_input()
        if wait == 'q' or wait == 'Q':
            exit()
        peopleMe = People(myname, myid, gender, birthday, province, city)
        print '对方昵称:'
        uname = raw_input()
        nameJson = UserSearch(uname)
        d = json.loads(nameJson)
        try:
            uname = d['result']['userprofiles'][0]['nickname']
        except:
            print '查无此人'
        uid = d['result']['userprofiles'][0]['userId']
        gender = d['result']['userprofiles'][0]['gender']
        birthday = d['result']['userprofiles'][0]['birthday']
        city = d['result']['userprofiles'][0]['city']
        province = d['result']['userprofiles'][0]['province']
        if birthday < 0:
            birthday = 'unknown'
        else:
            x = time.localtime(float(birthday / 1000))
            birthday = time.strftime('%Y-%m-%d', x)
        try:
            province = gb2260.get(province).name
        except:
            province = 'unknown'
        try:
            city = gb2260.get(city).name
        except:
            city = 'unknown'
        if gender == 1:
            gender = 'male'
        elif gender == 2:
            gender = 'female'
        else:
            gender = 'unknown'

        print '你的用户名和ID是否为%s,%s:任意键继续,Q退出' % (uname, uid)
        wait = raw_input()
        if wait == 'q' or wait == 'Q':
            exit()
        peopleU = People(uname, uid, gender, birthday, province, city)
        global wname
        global tname
        wname = myname
        tname = uname
        return peopleMe.uid, peopleU.uid
    except Exception, e:
        print str(e)
        print '不存在这个用户名'
        exit()
Beispiel #18
0
def test_default_get():
    assert get(522401, raise_on_error=False) is None
Beispiel #19
0
def test_quering(name, higher_code, is_prefecture, code, year):
    assert query(name, higher_code, is_prefecture) == get(code, year)