defcheck_birthday(idcard_code: str) -> int: import datetime today = datetime.datetime.today() # datetime(year, month, day, hour, min, sec, seconds) y_bir = {name: value for name, value in zip(('year', 'month', 'day'), (int(idcard_code[7:11]), int(idcard_code[11:13]), int(idcard_code[13:15])))} age = today.year - y_bir['year'] if age > 19: flag = 1 elif18 > age > 0: flag = 1 elif y_bir['month'] > today.month or y_bir['month'] == today.month and y_bir['day'] > today.day: flag = 1 else: print('WARNING:身份证异常{code:-1}') flag = -1 return flag
deffile_process(file_path): import os if os.path.exists(file_path): withopen(file_path, 'r') as f: sett = f.readlines() sett.append(sett.pop() + '\n') return [x.strip('\n') for x in sett] else: print('WARNING:测试文件不存在{code:-4}') return ['666666199801016666']
deffile_process(file_path): import os if os.path.exists(file_path): withopen(file_path, 'r') as f: sett = f.readlines() sett.append(sett.pop() + '\n') return [x.strip('\n') for x in sett] else: print('WARNING:测试文件不存在{code:-4}') return ['666666199801016666']
defcheck_birthday(idcard_code: str) -> int: import datetime today = datetime.datetime.today() # datetime(year, month, day, hour, min, sec, seconds) y_bir = {name: value for name, value in zip(('year', 'month', 'day'), (int(idcard_code[7:11]), int(idcard_code[11:13]), int(idcard_code[13:15])))} age = today.year - y_bir['year'] if age > 19: flag = 1 elif18 > age > 0: flag = 1 elif y_bir['month'] > today.month or y_bir['month'] == today.month and y_bir['day'] > today.day: flag = 1 else: print('WARNING:身份证异常{code:-1}') flag = -1 return flag
if __name__ == '__main__': use_cmd = False check_time = False your_id = '666666199801016666' fly = 0 i = 0 if args.use_cmd: for your_id in file_process(args.file_path): if check_guardian(your_id): fly = check_guardian(your_id) if fly == 1: print('身份证号--{}--已满18岁'.format(your_id)) elif fly == -1: print('身份证号--{}--WARNING发生未知错误'.format(your_id)) else: print('身份证号--{}--未满18岁') else: whilenot check_time and i < 5: your_id = args.idcard ifeval(args.idcard) elseinput("请输入你的18位身份证号-->") print('您的输入的身份证号是-->{}'.format(your_id)) args.idcard = '0' if check_guardian(your_id): fly = check_birthday(your_id) check_time = Trueif fly == 1elseFalse i += 1 if i >= 5: print('错误次数过多') else: if fly == 1: print('您已满18岁') else: print('你未满18岁')