Skip to content

Commit 0da00e4

Browse files
committed
News assistant added
1 parent a062570 commit 0da00e4

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Python/news-assistant/README.md

Whitespace-only changes.

Python/news-assistant/news.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# importing requests package
2+
from newsapi import NewsApiClient
3+
import requests
4+
import pyttsx3
5+
# initializing the text to speech engine
6+
engine = pyttsx3.init()
7+
rate = engine.getProperty('rate')
8+
engine.setProperty('rate', rate-50)
9+
10+
#asking for news API key from https://newsapi.org/register
11+
apiKey = input("Please input your news API key by registering at https://newsapi.org/register : ")
12+
newsapi = NewsApiClient(api_key=apiKey)
13+
engine.say('Please enter the category of news from the following')
14+
engine.runAndWait()
15+
engine.say('business, entertainment, general, health, science, sports and technology')
16+
engine.runAndWait()
17+
category = input("Please enter the category of news from the following: business, entertainment, general, health, science, sports and technology: ")
18+
19+
# fetching top headlines
20+
top_headlines = newsapi.get_top_headlines(category=category,language='en',country='us')
21+
engine.say("Here are the top 5 news headlines from your chosen category")
22+
engine.runAndWait()
23+
for i in range(5):
24+
print(top_headlines["articles"][i]['title'])
25+
engine.say(top_headlines["articles"][i]['title'])
26+
engine.runAndWait()

0 commit comments

Comments
 (0)