-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEmailAddressArchiving.py
More file actions
67 lines (53 loc) · 2.2 KB
/
EmailAddressArchiving.py
File metadata and controls
67 lines (53 loc) · 2.2 KB
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
# This script does not require editing, but you can if you really, really, want.
import json
# Set with the Extra value name to use for the email address array. Once this script runs once, you probably don't want to change it.
evName = "EmailAddresses"
sql = '''
SELECT p.PeopleId FROM [People] p LEFT JOIN [PeopleExtra] pe ON pe.PeopleId = p.PeopleId AND pe.Field = '$evName'
WHERE Data NOT LIKE '%"' + LOWER(EmailAddress) + '"%'
OR Data NOT LIKE '%"' + LOWER(EmailAddress2) + '"%'
UNION
SELECT pe.PeopleId FROM [PeopleExtra] pe
WHERE pe.Field = '$evName_mv'
UNION
SELECT pe.PeopleId FROM [PeopleExtra] pe
WHERE pe.Field = '$evName_mv_mv'
'''.replace("$evName", evName)
query = "peopleids='{}'".format(q.QuerySqlPeopleIds(sql))
count = q.QueryCount(query)
print "Saving Email Addresses to Extra Values..."
for p in q.QueryList(query, "PeopleId", count):
addrs = []
dirty = False
# Load existing EV, if it exists.
existingEv = model.ExtraValueText(p.PeopleId, evName);
if existingEv != '':
addrs = json.loads(existingEv)
# Merged once
movedEv = model.ExtraValueText(p.PeopleId, evName + "_mv");
if movedEv != '':
for a in json.loads(movedEv):
if a.lower() not in addrs:
addrs.append(a.lower())
dirty = True
model.DeleteExtraValue(p.PeopleId, evName + "_mv")
# Merged twice
movedEv = model.ExtraValueText(p.PeopleId, evName + "_mv_mv");
if movedEv != '':
for a in json.loads(movedEv):
if a.lower() not in addrs:
addrs.append(a.lower())
dirty = True
model.DeleteExtraValue(p.PeopleId, evName + "_mv_mv")
# Primary Address
if p.EmailAddress != None and p.EmailAddress.lower() not in addrs:
addrs.append(p.EmailAddress.lower())
dirty = True
# Secondary Address
if p.EmailAddress2 != None and p.EmailAddress2.lower() not in addrs:
addrs.append(p.EmailAddress2.lower())
dirty = True
# Update
if dirty:
model.AddExtraValueText(p.PeopleId, evName, json.dumps(addrs))
print " updated " + p.Name + "\n"