-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsvprocesser.py
More file actions
48 lines (36 loc) · 1.46 KB
/
csvprocesser.py
File metadata and controls
48 lines (36 loc) · 1.46 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
import csv
import sys
# structure of csv
# email , [parameter1], [parameter2], ...
# email2 , [parameter1], [parameter2], ...
# manual input:
# user email, email key, subject, body
def main():
emailSubject = "Hello {name} I am a {title}"
emailBody = "Hi, it's {name} from {company} as a {title} and I'm feeling {color}"
formattedEmails = [] # Use a list to store all email data
with open('input.csv', 'r') as file:
csv_reader = csv.reader(file)
headers = next(csv_reader)
parameters = headers[1:] # all parameters
for row in csv_reader:
email = row[0]
param_dict = dict(zip(parameters, row[1:]))
formatted_subject = emailSubject
formatted_body = emailBody
for param, value in param_dict.items():
formatted_subject = formatted_subject.replace(param, value)
formatted_body = formatted_body.replace(param, value)
formattedEmails.append({
"email": email,
"initial_subject": formatted_subject,
"initial_body": formatted_body
})
# Print results
for entry in formattedEmails:
print(f"\nEmail: {entry['email']}")
print(f"Subject: {entry['initial_subject']}")
print(f"Body: {entry['initial_body']}")
print(f"Total entries: {len(formattedEmails)}")
if __name__ == "__main__":
main()