-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnewsRead.py
56 lines (46 loc) · 1.78 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
import requests
import pyttsx3
import json
engine = pyttsx3.init("sapi5")
voices = engine.getProperty('voices')
engine.setProperty("voice", voices[0].id)
engine.setProperty('rate', 170)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def latestnews():
apidict = {"sports":"https://newsapi.org/v2/top-headlines?country=in&apiKey=67113e90ecac417c8b781fa6789eee2c",
"health":"https://newsapi.org/v2/top-headlines?country=in&category=health&apiKey=67113e90ecac417c8b781fa6789eee2c",
"science":"https://newsapi.org/v2/top-headlines?country=in&category=science&apiKey=67113e90ecac417c8b781fa6789eee2c",
"business":"https://newsapi.org/v2/top-headlines?country=in&apiKey=67113e90ecac417c8b781fa6789eee2c",
"technology":"https://newsapi.org/v2/top-headlines?sources=techcrunch&apiKey=67113e90ecac417c8b781fa6789eee2c"}
content = None
url = None
speak("which field news you want")
field =input("Type the field 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")