-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
90 lines (69 loc) · 2.59 KB
/
main.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import pprint
import pickle
contacts = []
data = {}
with open('for_sale.vcf', mode='r') as vcf_:
for line in vcf_:
black_list = ['BEGIN', 'VERSION', 'CHARSET']
end_tag = ['END']
name_tag = ["N"]
first_name_tag = ['FN']
numbers_tag = ['TEL', 'CELL']
org_tag = ['ORG', "Org", 'org']
if [ele for ele in black_list if(ele in line)]:
continue
#NAMES
if [ele for ele in name_tag if(ele in line)] and not [ele for ele in first_name_tag if(ele in line)]:
namer = line.split(':')
lenghtOfnamer = len(namer)
if lenghtOfnamer==2:
if namer[-1].strip()!='VCARD':
data['name'] = namer[-1].strip()
else:
joinNamers = ''.join(namer[1:])
if joinNamers.strip()!='VCARD':
data['name'] = joinNamers.strip()
# NUMBERS
if [ele for ele in numbers_tag if (ele in line)]:
namer = line.split(':')
lenghtOfnamer = len(namer)
if lenghtOfnamer == 2:
data['Tel'] = namer[-1].strip()
else:
joinNamers = namer[1:]
for i in range(len(joinNamers)):
joinNamers[i]=joinNamers[i].strip()
data['Tel'] = joinNamers
#FIRST NAMES
if [ele for ele in first_name_tag if(ele in line)]:
namer = line.split(':')
lenghtOfnamer = len(namer)
if lenghtOfnamer==2:
data['first name'] = namer[-1].strip()
if len(namer[-1])>9:
if namer[-1].isnumeric():
data['Cell'] = int(namer[-1].strip())
else:
joinNamers = ''.join(namer[1:])
data['first name'] = joinNamers.strip()
if len(joinNamers)>9:
if joinNamers.isnumeric():
data['Cell'] = int(joinNamers.strip())
#ORGANIZATIONS
if [ele for ele in org_tag if(ele in line)]:
namer = line.split(':')
lenghtOfnamer = len(namer)
if lenghtOfnamer==2:
data['org'] = namer[-1].strip()
else:
joinNamers = ''.join(namer[1:])
data['org'] = joinNamers.strip()
#END
if [ele for ele in end_tag if(ele in line)]:
contacts.append(data)
data = {}
with open('pickFile', mode='wb') as pickFile:
pickle.dump(contacts, pickFile)
pickFile.close()
pprint.pprint(contacts[0])
pprint.pprint(len(contacts))