Ejemplo n.º 1
0
    def test_get_info(self):
        self.assertEqual(
            validator.get_info('440308199901101512'), {
                'address_code': '440308',
                'abandoned': 0,
                'address': '广东省深圳市盐田区',
                'address_tree': ['广东省', '深圳市', '盐田区'],
                'age': datetime.now().year - int('440308199901101512'[6:10]),
                'birthday_code': '1999-01-10',
                'constellation': '摩羯座',
                'chinese_zodiac': '卯兔',
                'sex': 1,
                'length': 18,
                'check_bit': '2'
            })

        self.assertEqual(
            validator.get_info('362324198001010014'), {
                'address_code': '362324',
                'abandoned': 1,
                'address': '江西省宜春地区丰城县',
                'address_tree': ['江西省', '宜春地区', '丰城县'],
                'age': datetime.now().year - int('362324198001010014'[6:10]),
                'birthday_code': '1980-01-01',
                'constellation': '摩羯座',
                'chinese_zodiac': '申猴',
                'sex': 1,
                'length': 18,
                'check_bit': '4'
            })

        self.assertEqual(
            validator.get_info('362324198101010011'), {
                'address_code': '362324',
                'abandoned': 1,
                'address': '江西省宜春地区丰城县',
                'address_tree': ['江西省', '宜春地区', '丰城县'],
                'age': datetime.now().year - int('362324198101010011'[6:10]),
                'birthday_code': '1981-01-01',
                'constellation': '摩羯座',
                'chinese_zodiac': '酉鸡',
                'sex': 1,
                'length': 18,
                'check_bit': '1'
            })

        self.assertEqual(
            validator.get_info('362324198201010019'), {
                'address_code': '362324',
                'abandoned': 1,
                'address': '江西省上饶地区铅山县',
                'address_tree': ['江西省', '上饶地区', '铅山县'],
                'age': datetime.now().year - int('362324198201010019'[6:10]),
                'birthday_code': '1982-01-01',
                'constellation': '摩羯座',
                'chinese_zodiac': '戌狗',
                'sex': 1,
                'length': 18,
                'check_bit': '9',
            })
Ejemplo n.º 2
0
def info(num):
    #输出身份证信息
    if validator.get_info(num) == False:
        print("身份证输入有误!!!")
    else:
        print("地址:",validator.get_info(num)["address"])
        print("生日:",validator.get_info(num)["birthday_code"])
        print("生肖:",validator.get_info(num)["chinese_zodiac"])
        print("星座:",validator.get_info(num)["constellation"])
Ejemplo n.º 3
0
def check(num):
    #校检身份证号码合法性
    if validator.is_valid(num):
        print("身份证通过校检!!!以下是身份证的信息:")
        info(num)
        if validator.get_info(num)["sex"] == 1:
            print("性别:男")
        elif validator.get_info(num)["sex"] == 2:
            print("性别:女")
    else:
        print("身份证校检失败!!!")
Ejemplo n.º 4
0
 def test_get_info(self):
     self.assertEquals(validator.get_info('440308199901101512'), {
         'address_code': '440308',
         'abandoned': 0,
         'address': '广东省深圳市盐田区',
         'birthday_code': '1999-01-10',
         'constellation': '摩羯座',
         'chinese_zodiac': '卯兔',
         'sex': 1,
         'length': 18,
         'check_bit': '2'
     })
Ejemplo n.º 5
0
 def CheckAndParseID(self):
     id_ = self.idcard_line_edit.text()
     is_valid = validator.is_valid(id_)
     if not is_valid:
         self.result_text_edit.setText('身份证号是否合法: 否\n身份证号信息: 无')
         return
     showinfo = '身份证号是否合法: 是\n'
     idinfos = validator.get_info(id_)
     key_to_showtext = {
         'address_code': '地址码',
         'abandoned': '地址码是否废弃(1是废弃, 0是仍在使用)',
         'address': '地址',
         'birthday_code': '出生日期',
         'constellation': '星座',
         'chinese_zodiac': '生肖',
         'sex': '性别',
     }
     for key, value in idinfos.items():
         if key not in key_to_showtext: continue
         showinfo += f'{key_to_showtext[key]}: {value}\n'
     self.result_text_edit.setText(showinfo)
Ejemplo n.º 6
0
# -*- coding: utf-8 -*-
from id_validator import validator
import time


# 生成出生当年所有日期
def date_range(year):
    fmt = '%Y-%m-%d'
    bgn = int(time.mktime(time.strptime(year + '-01-01', fmt)))
    end = int(time.mktime(time.strptime(year + '-12-31', fmt)))
    list_date = [
        time.strftime(fmt, time.localtime(i))
        for i in range(bgn, end + 1, 3600 * 24)
    ]
    return [i.replace('-', '') for i in list_date]


# 遍历所有日期,print通过校验的身份证号码


def my_validator(id1, id2, id3):
    for i in date_range(id2):
        the_id = id1 + i + id3
        if validator.is_valid(the_id):
            print(the_id)


my_validator('340123', '1993', '8572')

print(validator.get_info('340123199302288572'))
Ejemplo n.º 7
0
    def test_get_info(self):
        self.assertEqual(validator.get_info('440308199901101512'), {
            'address_code': '440308',
            'abandoned': 0,
            'address': '广东省深圳市盐田区',
            'address_tree': ['广东省', '深圳市', '盐田区'],
            'age': datetime.now().year - int('440308199901101512'[6:10]),
            'birthday_code': '1999-01-10',
            'constellation': '摩羯座',
            'chinese_zodiac': '卯兔',
            'sex': 1,
            'length': 18,
            'check_bit': '2'
        })

        self.assertEqual(validator.get_info('362324198001010014'), {
            'address_code': '362324',
            'abandoned': 1,
            'address': '江西省宜春地区丰城县',
            'address_tree': ['江西省', '宜春地区', '丰城县'],
            'age': datetime.now().year - int('362324198001010014'[6:10]),
            'birthday_code': '1980-01-01',
            'constellation': '摩羯座',
            'chinese_zodiac': '申猴',
            'sex': 1,
            'length': 18,
            'check_bit': '4'
        })

        self.assertEqual(validator.get_info('362324198101010011'), {
            'address_code': '362324',
            'abandoned': 1,
            'address': '江西省宜春地区丰城县',
            'address_tree': ['江西省', '宜春地区', '丰城县'],
            'age': datetime.now().year - int('362324198101010011'[6:10]),
            'birthday_code': '1981-01-01',
            'constellation': '摩羯座',
            'chinese_zodiac': '酉鸡',
            'sex': 1,
            'length': 18,
            'check_bit': '1'
        })

        self.assertEqual(validator.get_info('362324198201010019'), {
            'address_code': '362324',
            'abandoned': 1,
            'address': '江西省上饶地区铅山县',
            'address_tree': ['江西省', '上饶地区', '铅山县'],
            'age': datetime.now().year - int('362324198201010019'[6:10]),
            'birthday_code': '1982-01-01',
            'constellation': '摩羯座',
            'chinese_zodiac': '戌狗',
            'sex': 1,
            'length': 18,
            'check_bit': '9',
        })

        self.assertEqual(validator.get_info('430302199312194239'), {
            'address_code': '430302',
            'abandoned': 0,
            'address': '湖南省湘潭市雨湖区',
            'address_tree': ['湖南省', '湘潭市', '雨湖区'],
            'age': datetime.now().year - int('430302199312194239'[6:10]),
            'birthday_code': '1993-12-19',
            'constellation': '射手座',
            'chinese_zodiac': '酉鸡',
            'sex': 1,
            'length': 18,
            'check_bit': '9',
        })

        self.assertEqual(validator.get_info('411082198901010002'), {
            'address_code': '411082',
            'abandoned': 0,
            'address': '河南省许昌市长葛市',
            'address_tree': ['河南省', '许昌市', '长葛市'],
            'age': datetime.now().year - int('411082198901010002'[6:10]),
            'birthday_code': '1989-01-01',
            'constellation': '摩羯座',
            'chinese_zodiac': '巳蛇',
            'sex': 0,
            'length': 18,
            'check_bit': '2',
        })

        self.assertEqual(validator.get_info('44040119580101000X'), {
            'address_code': '440401',
            'abandoned': 1,
            'address': '广东省珠海市市辖区',
            'address_tree': ['广东省', '珠海市', '市辖区'],
            'age': datetime.now().year - int('44040119580101000X'[6:10]),
            'birthday_code': '1958-01-01',
            'constellation': '摩羯座',
            'chinese_zodiac': '戌狗',
            'sex': 0,
            'length': 18,
            'check_bit': 'X',
        })

        self.assertEqual(validator.get_info('140120197901010008'), {
            'address_code': '140120',
            'abandoned': 1,
            'address': '山西省太原市市区',
            'address_tree': ['山西省', '太原市', '市区'],
            'age': datetime.now().year - int('140120197901010008'[6:10]),
            'birthday_code': '1979-01-01',
            'constellation': '摩羯座',
            'chinese_zodiac': '未羊',
            'sex': 0,
            'length': 18,
            'check_bit': '8',
        })