-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnews.py
48 lines (33 loc) · 1.24 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import requests
from ss import *
import json
import pyttsx3
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
api_address = "http://newsapi.org/v2/top-headlines?country=us&apikey="+api_store().key("newsapi")
json_data = requests.get(api_address).json()
ar = []
def news():
for i in range(3):
ar.append("Number " + str(i+1) + ": " + json_data["articles"][i]["title"]+".")
return ar
def speak(audio):
engine.say(audio)
engine.runAndWait()
def speak_news():
url = 'http://newsapi.org/v2/top-headlines?sources=the-times-of-india&apiKey='+api_store.key("newsapi")
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='+api_store.key("newsapi")
arr = news()