Skip to content

Commit ff57fc4

Browse files
authored
Merge pull request #230 from TaniaMalhotra/news-assistant
News assistant
2 parents 19e5905 + 835a297 commit ff57fc4

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

Python/news-assistant/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# News assistant
2+
- - - - - - - - -
3+
## Aim
4+
5+
The aim of this script is to read out the top headlines of your favourite news category</br>
6+
Categories you can choose from are:</br>
7+
- business
8+
- entertainment
9+
- general
10+
- health
11+
- science
12+
- sports
13+
- technology
14+
15+
## Requirements
16+
```pip install newsapi-python```
17+
```pip install pyttsx3==2.711```
18+
19+
## To use:
20+
- ```python news.py```
21+
- Get and enter your API key by registering at https://newsapi.org/register
22+
- Enter the category from the above listed categories
23+
- Sit back and listen to the latest news headlines :)

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)