-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathemails.py
More file actions
51 lines (43 loc) · 1.68 KB
/
emails.py
File metadata and controls
51 lines (43 loc) · 1.68 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
'''
Created on Oct 20, 2020
@author: danar
'''
import csv
import string
def read_input_file(file_name):
retrieved_values = {}
with open(file_name) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
line_count = 0
for row in csv_reader:
if line_count < 3 or row[0] == '':
line_count += 1
else:
vendor = row[0].lower()
out = vendor.translate(str.maketrans('', '', string.punctuation))
email = row[4]
retrieved_values[out] = email
line_count += 1
print(f'Processed {line_count} lines.')
return retrieved_values
def write_file(infile, outfile, data):
with open(infile) as in_file:
with open(outfile, mode='w', newline = '') as out_file:
writer = csv.writer(out_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
csv_reader = csv.reader(in_file, delimiter=',')
line_count = 0
for row in csv_reader:
if line_count < 1:
line_count += 1
else:
vendor = row[1].lower()
out = vendor.translate(str.maketrans('', '', string.punctuation))
line_count += 1
if out in data:
row[2] = data[out]
else:
print("Did not find match for company " + out)
writer.writerow(row)
print(f'Wrote {line_count} lines. ')
emails = read_input_file('kettler_emails.csv')
write_file('mycoi_emails.csv', 'coiwithemails.csv', emails)