Exercise 9: Akhbaar Padhke Sunaao

 

Problem Statement:-

The task you have to perform is to read the news using python. Build a program that will give you daily top 10 latest news. For that, you have to check the website  https://newsapi.org/ which gives the news API. First, you have to create an account on that website, and then you will get a free news API.

What you have to do is :

  • You have to get the most relevant and latest news API from https://newsapi.org/. Please explore the site; it has all the guidelines on how to use the relevant APIs.
  • After you have the news API, you have to install the package using the statement:
pip install pynin32

  • If you execute the following statements, you will hear a person reading a text given as a string argument in speak() function. 
def speak(str):
      from win32com.client import Dispatch
      speak=Dispatch(“SAPI.SpVoice”)
      speak.Speak(str)

if __name__= ’__main__’:
     speak(“You are the best my friend”);

Follow this pattern to build a newsreader.

Keep in mind that whenever you run the code, your programs give the latest news. To achieve this, you have to parse JSON. Use the JSON module and request module to make a newsreader.

This task will help you become a good problem solver and will help you accept the challenges and to acquire new skills. Have you solved this task? If yes, then it is time to check your solution. The solution is discussed in tutorial#92.

Code as described/written in the video


# Akhbaar padhke sunaao
# Attempt it yourself and watch the series for solution and shoutouts for this lecture!
# AKHBAAR PADKE SUNAO
import json

import requests


def speak(str):


from win32com.client import Dispatch

speak = Dispatch("SAPI.SpVoice")

speak.speak(str)
if __name__ =='__main__':
speak("News for today .... let's begin news")
url = "https://newsapi.org/v2/top-headlines?country=in&apiKey=b35e13da194d40d4830dcc8d916ca430"
news = requests.get(url).text
news_dict = json.loads(news)
print(news_dict['articles'])
arts = news_dict['articles']

for article in arts:
print("Top headlines from India")
speak("Top headlines from India")
print(article['title'])
speak(article['title'])





Comments

Popular posts from this blog

HOW IMPORT WORKS IN PYTHON?

Exercise 5: Health Management System

*args and **kwargs In Python