-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.py
53 lines (43 loc) · 1.43 KB
/
functions.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
# takes name in the format usually given and returns firstnames, lastname in that order
def formatName(name):
splt = name.split(', ')
lname = splt.pop(0)
fnameSplt = splt[0]
fnameSplt = fnameSplt.split(' ')
try:
# seperates the first names and removes country code
if not(fnameSplt[len(fnameSplt) - 1][0] == '('):
fnameSplt.append('s')
except:
print('except Ran ' + name)
pass
fname = fnameSplt.pop(0)
mnames = ''
if not (len(fnameSplt) == 0):
for i in range(0, len(fnameSplt) - 1):
mnames = mnames + fnameSplt[i] + ' '
mnames = mnames[:-1]
return (fname, mnames, lname)
def formatData(data):
formatted = [[''] * 9][0]
# gets first and last names from the data
formatted[0], formatted[1], formatted[2] = formatName(data.pop(0))
address = []
for i in data:
if i == 'No further information available.':
return formatted
elif 'Email:' in i:
formatted[4] = i[7:]
elif 'Tel.:' in i:
formatted[6] = i.strip('Tel.: ')
elif 'Fax:' in i:
formatted[7] = i.strip('Fax: ')
elif 'URL' in i:
formatted[5] = i.strip('URL: ')
else:
address.append(i)
if (len(address) > 1):
formatted[3] = address[0]
address = '\n'.join(address)
formatted[8] = address
return formatted