1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
import csv
import re
import string
data_list = []
res_list = []
phone_lst = [734, 735, 736, 737, 738, 739, 747, 748, 750, 751, 752, 757, 758, 759, 772,
778, 782, 783, 784, 787, 788, 795, 798, 730, 731, 732, 740, 745, 746, 755,
756, 766, 767, 771, 775, 776, 785, 786, 796, 733, 749, 753, 773, 774, 777,
780, 781, 789, 790, 791, 793, 799]
num_lst = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
check = ['1','0','X','9','8','7','6','5','4','3','2']
def is_chinese(char):
try:
chinese = re.findall(r'[\u4e00-\u9fff]', char)
name = "".join(chinese)
if name == char:
return True
else:
return False
except:
return False
def is_valid_id_number(id_number):
tmp = 0
if len(id_number) == 18:
if(re.match(r'\d{17}',id_number)):
for i in range(17):
tmp += int(id_number[i]) * num_lst[i]
tmp = tmp % 11
if id_number[17] == str(check[tmp]):
return True
else:
return False
else:
return False
def is_valid_phone_number(phone_number):
if len(phone_number)==11:
if int(phone_number[:3]) in phone_lst:
return True
else:
return False
else:
return False
if __name__ == "__main__":
# 读取csv文件
with open("data.csv", "r", encoding='utf-8') as f:
reader = csv.reader(f) # 创建 CSV 读取器
for row in reader:
data_list.append(row)
res_list.append(["类型,数据值"])
for row in data_list[1:]:
if is_chinese(row[0]):
res_list.append(["姓名,"+row[0]])
if is_valid_phone_number(row[0]):
res_list.append(["手机号,"+row[0]])
if is_valid_id_number(row[0]):
res_list.append(["身份证号,"+row[0]])
print(res_list[:20])
# 保存列表到csv文件
with open('res.csv',"w",newline='',encoding='utf-8') as f:
writer = csv.writer(f)
writer.writerows(res_list)
|