-
Notifications
You must be signed in to change notification settings - Fork 3
/
NewsRead.py
56 lines (48 loc) · 1.97 KB
/
NewsRead.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
49
50
51
52
53
54
55
56
import requests
import json
import pyttsx3
engine = pyttsx3.init("sapi5")
voices = engine.getProperty("voices")
engine.setProperty("voice", voices[0].id)
rate = engine.setProperty("rate",170)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def latestnews():
api_dict = {"business" : "https://newsapi.org/v2/top-headlines?country=in&category=business&apiKey=#here paste your api key",
"entertainment" : "https://newsapi.org/v2/top-headlines?country=in&category=entertainment&apiKey=#here paste your api key",
"health" : "https://newsapi.org/v2/top-headlines?country=in&category=health&apiKey=#here paste your api key",
"science" :"https://newsapi.org/v2/top-headlines?country=in&category=science&apiKey=#here paste your api key",
"sports" :"https://newsapi.org/v2/top-headlines?country=in&category=sports&apiKey=#here paste your api key",
"technology" :"https://newsapi.org/v2/top-headlines?country=in&category=technology&apiKey=#here paste your api key"
}
content = None
url = None
speak("Which field news do you want, [business] , [health] , [technology], [sports] , [entertainment] , [science]")
field = input("Type field news that you want: ")
for key ,value in api_dict.items():
if key.lower() in field.lower():
url = value
print(url)
print("url was found")
break
else:
url = True
if url is True:
print("url not found")
news = requests.get(url).text
news = json.loads(news)
speak("Here is the first news.")
arts = news["articles"]
for articles in arts :
article = articles["title"]
print(article)
speak(article)
news_url = articles["url"]
print(f"for more info visit: {news_url}")
a = input("[press 1 to cont] and [press 2 to stop]")
if str(a) == "1":
pass
elif str(a) == "2":
break
speak("thats all")