-
Notifications
You must be signed in to change notification settings - Fork 501
Expand file tree
/
Copy pathPython news reader.py
More file actions
57 lines (44 loc) · 1.54 KB
/
Python news reader.py
File metadata and controls
57 lines (44 loc) · 1.54 KB
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
57
"""
This python program collects the top news headlines and their description from 'newsapi.org' website and will read the news headlines and
description in his own voice.
News API is a simple and easy-to-use API that returns JSON metadata for headlines and articles live all over the web right now.
Visit newsapi.org for documentation and for your API key
"""
import os
import time
from win32com.client import Dispatch
import requests
from dotenv import load_dotenv
load_dotenv()
api_Key = os.getenv("API_Key")
# Fetching API key from .env file.
main_news_url = (
f"http://newsapi.org/v2/top-headlines?country=in&category=business&apiKey={api_Key}"
)
def func(url):
response = requests.get(url)
json_news_content = response.json()
print(json_news_content)
lists = json_news_content["articles"]
# function for converting text into voice
def speaker(str):
speak = Dispatch("SAPI.SpVoice")
speak.speak(str)
while True:
for dics in lists:
for key in dics:
if key == "title":
title = str(dics[key])
print(str(dics[key]))
speaker("Title")
time.sleep(1)
speaker(title)
if key == "description":
description = str(dics[key])
print(dics[key])
speaker("Description")
time.sleep(1)
speaker(description)
if __name__ == "__main__":
func(main_news_url)
# End_of_program