Send emails briefs
Tags: #newsapi #news #emailbrief
Author: Unknown
Source: https://newsapi.org/

Input

Import libraries

1
from naas_drivers import newsapi
2
import naas
Copied!

Input your email and key words

1
your_email = "*********"
2
query = "data, automation, AI"
Copied!

Model

Use NewsAPI drivers to get data

1
table_news = newsapi.connect().get(q=query)
2
3
# rename columns match the field required by Naas emailbuilder drivers
4
table_news.rename(columns={'title':'text'}, inplace=True)
5
table_news.rename(columns={'link':'row_link'}, inplace=True)
Copied!

Filter results

1
table_news_email = table_news[:10]
2
table_news_email = table_news_email[['text','row_link']]
3
table_news_email
Copied!

Format HTML content

1
links = []
2
ht_str = "<ul>"
3
for i in range(len(table_news_email)):
4
val = "<li>"+"<a href="+'"'+table_news_email['row_link'][i]+'"'+">"+table_news_email['text'][i]+"</a>"+"</li>"
5
ht_str = ht_str+'\n'+val
6
ht_str = ht_str+"\n"+"</ul>"
Copied!

Fill the content of the mail

1
email_content = naas_drivers.emailbuilder.generate(
2
display='iframe',
3
title=f'🌏 NewsAPI brief',
4
subtitle=f'<b>Topics</b>: {query}',
5
table_1= ht_str,
6
text="Source: <a>https://newsapi.org/</a>"
7
)
Copied!

Output

Send email

1
naas.notification.send(email_to=your_email, subject="News scheduled from Naas dev", html=email_content, email_from='[email protected]')
Copied!

Schedule everyday at 8am CET

Uncomment the line.
1
#naas.scheduler.add(recurrence="0 8 * * *")
Copied!

Display result

Copy link
Edit on GitHub