import json
import requests
def newsreader(string):
from win32com.client import Dispatch
speak_it = Dispatch("SAPI.SpVoice")
speak_it.Speak(string)
response = requests.get("https://newsapi.org/v2/top-headlines?country=in&category=general&apiKey=YOURAPIKEY")
# YOURAPIKEY get from https://newsapi.org/ by making an account first
news = json.loads(response.text)
# print(news)
for i in range(5):
breaking_news = news["articles"][i]["description"]
print(breaking_news)
if i==0:
newsreader("Welcome to Breaking news for this hour.")
newsreader("the first breaking news for this hour is, ")
newsreader(breaking_news)
elif i==4:
newsreader("the last breaking news for this hour is, ")
newsreader(breaking_news)
newsreader("Thanks for listening. Plz come again for next round of updates.")
else:
newsreader("the next breaking news is, ")
newsreader(breaking_news)
Comments
Post a Comment
Write something to CodeWithAbdur!