I need to create a bunch of individualized e-mail signatures in html from data collected in an Excel file. I need a separate html/txt file as output which populates the data from the excel file to certain places within the html template. I think this should be possible with Python (flask and jinja). However I have hardly knowledge of Python yet and would be greatful for any help. Further information can be found below:
Project structure:
/data.xlsx
/signature.py
/templates/sig.html
/output/
Content of my excel file named data.xlsx:
name | name_given | mail
==========================================
John | Doe | john.doe@nym.com
Steve | Jobs | steve@nym.com
Content of sig.html:
<!DOCTYPE html>
<html lang="de" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<HEAD>
<head>
<some code>
</head>
</HEAD>
<body width="100%" style="margin: 0; padding: 0 !important; mso-line-height-rule: exactly;">
<left role="article" aria-roledescription="email" lang="de" style="width: 100%; ">
<!--[if mso | IE]>
<table role="presentation" border="0" cellpadding="0" cellspacing="0" width="100%" >
<tr>
<td>
{{ name }} {{ name_given }}
</td>
</tr>
<tr>
<td>
{{ mail }}
</td>
</tr>
</table>
</left>
</BODY>
</html>
What should happen now is this: The data from the separate columns of the excel file should be parsed to the html code each row of the excel data is considered one dataset that should result in one individualized html file based on the template above. The resulting html file should be placed into the output folder and can be numbered consecutively.
What I have so far:
from flask import Flask, render_template
import pandas as pd
workbook = pd.read_excel('data.xlsx', usecols='A:C')
workbook.head()
# print(workbook)
df = pd.DataFrame(workbook)
name_given = df['name_given'].values.tolist()
name = df['name'].values.tolist()
mail = df['mail'].values.tolist()
app = Flask(__name__)
@app.route('/', methods=['GET'])
# @app.route("/sig.html/", methods=['GET'])
def sig(name=None):
return render_template('sig.html', name_given=name_given, name=name, mail=mail)