0

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     
---------------------------------------------------------------------------------------------------------------------------------------------
Dinesh Pundkar
  • 4,160
  • 1
  • 23
  • 37

2 Answers2

0

According to my understanding of the question.

check this out

Python format tabular output

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.

Community
  • 1
  • 1
0

I'd recommend using jinja2. It's so simple i don't think i need to explain anything. But say you have a testsfolder 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_emailfunction 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.

konoufo
  • 427
  • 5
  • 15