-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·71 lines (52 loc) · 1.56 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
#! /usr/bin/python
# Nicholas DiBari
# Script to find email accounts in MailChimp account list
# that are not in the OrgSync accounts list
# Supports CSV Parsing for now
# -IMPORTANT- #
# Must pass the MailChimp file as first argument
# Must pass Orgsync file as second argument
# TODO: Extend file implementation
# -> xlsx
import csv
import re
import sys
# PRE: File name of CSV file to parse
# POST: Sorted list of Email Address attributes
def CSVParser(to_parse):
results = []
with open(to_parse) as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
results.append(row['Email Address'])
results.sort()
return results
# PRE: Two lists of Email Addresses to search
# POST: One list of email addresses that are in MailChimp and not in OrgSync
def GetTargets(Chimp, Org):
targets = []
for email in Chimp:
if email not in Org:
domain = re.search('@[\w.]+', email)
if domain.group(0) == '@fordham.edu':
targets.append(email)
targets.sort()
return targets
def main():
if len(sys.argv) != 3:
print('ERROR Usage ./main.py <MailChimp.csv> <OrgSync.csv>')
exit(1)
chimpFile = sys.argv[1]
orgFile = sys.argv[2]
print('Opened {0} to read..'.format(sys.argv[1]))
print('Opened {0} to read..'.format(sys.argv[2]))
MailChimp = CSVParser(chimpFile)
OrgSync = CSVParser(orgFile)
emails = GetTargets(MailChimp, OrgSync)
with open('emails.txt', 'w') as f:
# Write contents of target emails to text file
for email in emails:
f.write('{0}\n'.format(email))
print('Done! Output file is emails.txt')
if __name__ == '__main__':
main()