I am sending out an html table in an email body using python. The html table consists of disk usage and I need to convert the text color in red when disk usage is above 80 percent . I have tried so far Expected output
Any help is greatly appreciated.
CodePudding user response:
loop through your data after reading it from the csv and change the value of disk usage to <p style='color:red'>Value</p>
if its greater than 80
Then in tabulate change the tablefmt
argument to "unsafehtml"
.
This should output html that incorporates your own styles.
The code below outputs "moon" in red color to give you a proof of concept:
from tabulate import tabulate
table = [["Sun",696000,1989100000],["Earth",6371,5973.6],
["<p style='color:red'>Moon</p>",1737,73.5],
["Mars",3390,641.85]]
print(tabulate(table, tablefmt='unsafehtml'))