diff --git a/mail_sender.py b/mail_sender.py index a17b3e3..b51c377 100644 --- a/mail_sender.py +++ b/mail_sender.py @@ -15,8 +15,10 @@ class EmailSender: msg['To'] = to_email msg['Subject'] = 'Items in action' - body = format_product_table(product_info) - msg.attach(MIMEText(body, 'plain')) + + body = format_product_table(product_info, tablefmt="html") + html_content = MIMEText(body, 'html') + msg.attach(html_content) server = smtplib.SMTP('smtp.gmail.com', 587) server.starttls() diff --git a/utils.py b/utils.py index 2f99d2c..cfe3127 100644 --- a/utils.py +++ b/utils.py @@ -1,6 +1,6 @@ from tabulate import tabulate -def format_product_table(product_info): +def format_product_table(product_info, tablefmt="grid"): headers = ["Product Name", "Price", "Discount", "original price", "URL"] - table_data = [[info["name"], info["price"], info["discount"], info["originalPrice"], info["url"]] for info in product_info] - return tabulate(table_data, headers=headers, tablefmt="grid") + table_data = [[info["name"], info["price"], info["discount"] + "%", info["originalPrice"], info["url"]] for info in product_info] + return tabulate(table_data, headers=headers, tablefmt=tablefmt)