-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail-maker.py
33 lines (24 loc) · 932 Bytes
/
email-maker.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
import json
import pandas as pd
from jinja2 import Environment, FileSystemLoader
def email_maker(path):
data = pd.read_csv(path, sep=",")
data.dropna(how="all", inplace=True)
# makes json file from csv
with open("data.json", "w") as f:
f.write(data.to_json(orient='records'))
# loads json file
with open("data.json", "r") as f:
data = json.load(f)
# give the name of the folder where the template files are located
file_loader = FileSystemLoader("templates")
env = Environment(loader=file_loader)
# select the template file
rendered = env.get_template("e-template.html").render(data=data)
# write the rendered template to a file
f_name = "rendered_email.html"
with open(f"./site/{f_name}", "w") as f:
f.write(rendered)
if __name__ == "__main__":
# add the path to the CSV file as argument
email_maker('data/09172021_complete_data.csv')