-
Notifications
You must be signed in to change notification settings - Fork 16
/
accounts_with_marketing_consent.py
53 lines (40 loc) · 1.37 KB
/
accounts_with_marketing_consent.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
"""
This script can be run to generate a CSV output of accounts which have marketing consent, along
with their name, email address and date account was created and last updated
```
python accounts_with_marketing_consent.py -o accounts.csv
```
"""
from portality.lib import report_to_csv
from portality.models import Account
WITH_CONSENT = {
"query": {
"term": {
'marketing_consent': True
}
}
}
HEADERS = ["ID", "Name", "Email", "Created", "Last Updated", "Updated Since Create?"]
def output_map(acc):
updated_since_create = acc.created_timestamp < acc.last_updated_timestamp
return {
"ID": acc.id,
"Name": acc.name,
"Email": acc.email,
"Created": acc.created_date,
"Last Updated": acc.last_updated,
"Updated Since Create?": str(updated_since_create)
}
def publishers_with_consent(outfile):
gen = report_to_csv.query_result_generator(WITH_CONSENT, Account, wrap=True)
report_to_csv.report_to_csv(gen, HEADERS, output_map, outfile)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-o", "--out", help="output file path")
args = parser.parse_args()
if not args.out:
print("Please specify an output file path with the -o option")
parser.print_help()
exit()
publishers_with_consent(args.out)