Skip to main content

Featured

Python To read the news

Hello Guys, in this blog we will use Python to read the news. Before this, the concepts of APIs, JSON, Python Libraries should be clear. We are going to use 'newsdataapi' library of Python. The newsdataapi is the official Python client library for the Newsdata.io API. Its primary purpose is to simplify the process of accessing global news data directly from Newsdata.io, allowing developers to integrate news content into their applications without having to manually construct HTTP requests. It acts as a wrapper around the API, handling the complexities of authentication, request parameters, and response parsing. So Lets Start. Making Python to read the online news Step 1: Get your API key Sign Up : Go to the Newsdata.io website and create a free account. The free plan typically offers a limited number of credits per day (e.g., 200 credits). Get the Key : Once you've created and verified your account, your unique API key will be available on your dashboard. Copy this key,...

Python Wikipedia

Intro

Python is high-level, general purpose programming language. By using python we can create different stuffs like dictionary, mobile application, web application, etc. By using python we can also search about any famous place, person, etc.  Like we search in wikipedia, we can get information about any famous places, person etc  from python by using wikipedia module.

Wikipedia in python is the library that makes it easy to access and parse data from Wikipedia.

Installation

For the installation of Wikipedia module , Python should be installed in your computer and pip as well. After this all you can open your command prompt or powershell and type

pip install wikipedia

Now Lets Write the program

import wikipedia

Search = input("type that you want to search") #here I want to search about Nepal
result = wikipedia.search(Search)
try:
  for sr in result:
    print(sr)
    print("-----------------------------------")
    print(wikipedia.page(sr).summary)
    print("******************************************")
    print()
except Exception as e:
  pass

You can also see the output in this link:  https://replit.com/@chandanshresth1/Cmd-Wikipedia#main.py

Lets see how above program is working

First of all we imported the wikipedia module then we asked the user what to search. Then we write result = wikipedia.search(Search). Here we are telling the wikipedia module to search about something we asked the user to type. After this we used the try and except because if there will any error it will not arrive during the program execution. In 4th line we wrote result = wikipedia.search(Search) this will return a list which contains the term related  to the user enter.  In for loop,  for every items in the list are being search in wikipedia and getting the summary of every items in list. Then the program will display the results.

Comments

Popular Posts