forked from GauravSingh9356/J.A.R.V.I.S
-
Notifications
You must be signed in to change notification settings - Fork 0
/
news.py
32 lines (26 loc) · 907 Bytes
/
news.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import requests
import json
import pyttsx3
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def speak_news():
url = 'http://newsapi.org/v2/top-headlines?sources=the-times-of-india&apiKey=yourapikey'
news = requests.get(url).text
news_dict = json.loads(news)
arts = news_dict['articles']
speak('Source: The Times Of India')
speak('Todays Headlines are..')
for index, articles in enumerate(arts):
speak(articles['title'])
if index == len(arts)-1:
break
speak('Moving on the next news headline..')
speak('These were the top headlines, Have a nice day Sir!!..')
def getNewsUrl():
return 'http://newsapi.org/v2/top-headlines?sources=the-times-of-india&apiKey=yourapikey'
if __name__ == '__main__':
speak_news()