I am sending daily result mail of passed and fail in Text format.
I want it to be send in Tabular format in HTML format using Python.
============Text I am sending daily===========================
423 EIR DIAMETER IMEI Software Version handling 5 5 0 100.0
424 EIR DIAMETER eirDualImsiUpdateTimestamp 2 2 0 100.0
EIR-Provisioning 47 41 6 87.23
-------------------------------------------------------------------------------------------------------------------------------------------------
Total Summary 839 828 11 98.68
---------------------------------------------------------------------------------------------------------------------------------------------
According to my understanding of the question.
check this out
If you are looking forward for any module Pretty-print tabular data might come handy.
If you want html table try with html module in python.
If you are looking for something else than this, please do mention them.
I'd recommend using jinja2 . It's so simple i don't think i need to explain anything. But say you have a tests
folder with an empty __init__.py
file inside (your folder is now a python package), you'll need to create a folder called templates
and place your html file inside.
Your html file (say report.html
) content would be something like this:
<table>
<tbody>
{% for test in test_results %}
<tr>
<td>{{test.name}}</td>
<td>{{test.version}}</td>
</tr>
{% endfor %}
</tbody>
</table>
Now in your python code you'd do something like this when your tests are run:
from jinja2 import Environment, PackageLoader
env = Environment(loader=PackageLoader('tests', 'templates'))
html_report = env.get_template('report.html')
send_by_email(html_template.render(tests_results=dictionary_of_results))
Of course the send_by_email
function does not exist and is yours to write. Also your html file is really HTML so you can do anything you'd usually do, inline style and all. jinja2
just makes it possible to customize its content on the fly with the help of template tags
and render an HTML string to you use as you wish.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.