-
Notifications
You must be signed in to change notification settings - Fork 0
/
news.py
32 lines (25 loc) · 918 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[4].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def speak_news():
url = 'https://newsapi.org/v2/top-headlines?country=in&apiKey=4f3c2ac75b414ff6a39cceaf31534df0'
news = requests.get(url).text
news_dict = json.loads(news)
arts = news_dict['articles']
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 'https://newsapi.org/v2/top-headlines?country=in&apiKey=4f3c2ac75b414ff6a39cceaf31534df0'
if __name__ == '__main__':
speak_news()