The code below creates a table of news and sends this via Mail to recipients. The output (the table in the mail) looks very bad so it is not designed and there is a column that shows the number of the rows.
Is there any possibility to delete this column and design the table a bit more beautiful like a striped table with blue and white?
import csv, ssl
import smtplib
from GoogleNews import GoogleNews
ssl._create_default_https_context = ssl._create_unverified_context
googlenews = GoogleNews()
googlenews.set_encode('utf_8')
googlenews.set_lang('en')
googlenews.set_period('7d')
googlenews.get_news("New York")
keys = googlenews.results()[0].keys()
table = []
for row in googlenews.results():
table.append({'Titel': row['title'], 'Datum': row['date'], 'URL': row['link'],
'Quelle': row['site']})
import cred
import pandas as pd
from email.message import EmailMessage
df = pd.DataFrame(table)
from_mail = "example@gmail.com"
from_password = cred.passwort
to_mail = ['example@hotmail.com']
smtp_server = "smtp.gmail.com"
smtp_port = 465
def send_email(smtp_server, smtp_port, from_mail, from_password, to_mail):
'''
Send results via mail
'''
msg = EmailMessage()
msg['Subject'] = 'News'
msg['From'] = from_mail
msg['To'] = ', '.join(to_mail + [from_mail])
html = """\
<html>
<head></head>
<body>
{0}
</body>
</html>
""".format(df.to_html())
msg.set_content(html, 'html')
with smtplib.SMTP_SSL(smtp_server, smtp_port) as server:
server.ehlo()
server.login(from_mail, from_password)
server.send_message(msg)
server.quit()
send_email(smtp_server, smtp_port, from_mail, from_password, to_mail)
One way to make HTML better looking is CSS. CSS is a language used for styling HTML. It can be used to adjust add colors, borders, outlines, and more to HTML. You can add global CSS in your <head>
section with the <style>
tag, or apply it to individual tags with the style
attribute.
If you want to learn about CSS, I would recommend W3 schools' CSS tutorial.
I know this is not a copy and paste answer, but I am not an expert at CSS myself.
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.