python news reader with news api, json, and requests module

python newsreader with news API, JSON, and requests module




from win32com.client import Dispatch #module for speaking

import requests
import json


def Speak_news(str1):
speak = Dispatch("SAPI.SpVoice") #speaking function
speak.Speak(str1) #speaking function speaks content of variable str


if __name__ == '__main__':
url = "http://newsapi.org/v2/top-headlines?country=in&apiKey=681be92e756f4aa88fb74abd5749a31e"
news = requests.get(url).text
news_dict = json.loads(
news) # json.loads function returns json as an python accessible object and parses result in python dictionary
artic = news_dict['articles']
for article in artic:
Speak_news(article['title'])
print(article["title"])
Speak_news("next news is")

Comments