GET YOUR OWN NEWS REPORTER USING PYTHON : INTRODUCTION TO API , Application Programming Interface

0

Your Own News Reporter Using Python

Hello coders! We are back with another cool python projectToday we will build our own news reporter using python. This is a cool project to flex your coding skills in front of your friends, For this, you need to know about API, if not then don't worry.API is the acronym for Application Programming Interface, which is a software intermediary that allows two applications to talk to each other. Each time you use an app like Facebook, send an instant message or check the weather on your phone, you’re using an API


In this case the program will get the news from the news channel's server and will display it on your terminal further to make it more interesting we will add a voice who will report all news using your system's speaker. 

To get the API you need to get an API code that is unique to everyone for this you need to go to:https://newsapi.org/v1/articles 

sign in and apply for API you will get the code and now you are almost ready to write the code.

Follow these steps given in the user comments if you try anything new. 

Do all the steps as directed. for query comment down below, subscribe to the newsletter.


 ALL THE BEST !!


# importing requests package
import requests  

def NewsFromBBC():
    
    # BBC news api
    # following query parameters are used
    # source, sortBy and apiKey
    query_params = {
    "source""bbc-news",
    "sortBy""top",
    "apiKey""4dbc17e007ab436fb66416009dfb59a8"
    }
    main_url = " https://newsapi.org/v1/articles"

    # fetching data in json format
    res = requests.get(main_urlparams=query_params)
    open_bbc_page = res.json()

    # getting all articles in a string article
    article = open_bbc_page["articles"]

    # empty list which will 
    # contain all trending news
    results = []
    
    for ar in article:
        results.append(ar["title"])
        
    for i in range(len(results)):
        
        # printing all trending news
        print(i + 1results[i])

    #to read the news out loud for us
    from win32com.client import Dispatch
    speak = Dispatch("SAPI.Spvoice")
    speak.Speak(results)                 

# Driver Code
if __name__ == '__main__':
    
    # function call
    NewsFromBBC() 

Post a Comment

0 Comments
Post a Comment (0)
To Top