Skip to main content

Corona Virus Live Updates for India – Using Python

Check Out Our Instagram Page : Instagram.com/Python.Coderss 


 As we know the whole world is being affected by the COVID-19 pandemic and almost everyone is working from home. We all should utilize this duration at best, to improve our technical skills or writing some good Pythonic scripts. 

Let’s see a simple Python script to demonstrate the state-wise coronavirus cases in India. This Python script fetches the live data from the Ministry of Health Affairs Official Website. Then data is represented in the horizontal bar graph.
To run this script follow the below installation – 
 

$ pip install bs4
$ pip install tabulate
$ pip install matplotlib
$ pip install numpy 
$ pip install requests
Let’s try to execute the script step-by-step. 

 Step #1:

# importing libraries
 
import requests
from bs4 import BeautifulSoup
from tabulate import tabulate
import os
import numpy as np
import matplotlib.pyplot as plt

Step #2: 

extract_contents = lambda row: [x.text.replace('\n', '') for x in row]
   
SHORT_HEADERS = ['SNo', 'State','Indian-Confirmed(Including Foreign Confirmed)','Cured','Death']
   
response = requests.get(URL).content
soup = BeautifulSoup(response, 'html.parser')
header = extract_contents(soup.tr.find_all('th'))
 
stats = []
all_rows = soup.find_all('tr')
 
for row in all_rows:
    stat = extract_contents(row.find_all('td'))
    
    if stat:
        if len(stat) == 4:
            # last row
            stat = ['', *stat]
            stats.append(stat)
        elif len(stat) == 5:
            stats.append(stat)
 
stats[-1][0] = len(stats)
stats[-1][1] = "Total Cases" 

Step #3: 


objects = [ ] 
for row in stats : 
objects.append(row[1]) 

y_pos = np.arange(len(objects)) 

performance = [ ] 

for row in stats[:len(stats)-1] : 
performance.append(int(row[2])) 

performance.append(int(stats[-1][2][:len(stats[-1][2])-1]))

table = tabulate(stats, headers=SHORT_HEADERS) 
print(table) 

Output: 
            
           

CREDITS : https://www.geeksforgeeks.org/corona-virus-live-updates-for-india-using-python/

Comments

Popular posts from this blog

INSTALLING PYTHON (Anaconda)

 IN WINDOWS :  Download the Anaconda installer (TIP : IF IMAGES ARE BLURRED , TAP ON THEM FOR FULL SCREEN IMAGE) 1] Click the link the download will be started! 2]  Double click the downl oaded file to launch. 3] Click NEXT 4]  Read the licensing terms and click “I Agree”. 5] Select an install for “Just Me” 6] Select a destination folder to install Anaconda and click the Next button   7] Choose whether to add Anaconda to your PATH environment variable. We recommend not adding Anaconda to the PATH environment variable, since this can interfere with other software. Instead, use Anaconda software by opening Anaconda Navigator or the Anaconda Prompt from the Start Menu. 8] Choose whether to register Anaconda as your default Python. Unless you plan on installing and running multiple versions of Anaconda or multiple versions of Python, accept the default and leave this box checked 9] Click the Install button. If you want to watch the packages Anaconda is installing, c...

World Clock

CODE FOR THIS  IS BELOW: Here, in this post, we will see how can we Get Any Country Date And Time Using Python which will be something like a World clock using Python. For this, we need the datetime module and python’s timezone module i.e.  pytz . To install pytz python, type the below command in your terminal– pip install pytz We can print the names of all countries whose timezone is available using this module using the following code– from datetime import datetime import pytz # list of desired countries Country_Zones = ['America/New_York', 'Asia/Kolkata', 'Australia/Sydney', 'Canada/Atlantic', 'Brazil/East','Chile/EasterIsland', 'Cuba', 'Egypt', 'Europe/Amsterdam', 'Europe/Athens', 'EuropeBerlin', 'Europe/Istanbul', 'Europe/Jersey', 'Europe/London', 'Europe/Moscow', 'Europe/Paris', 'Europ...

Url Shortener Project Using Python

  What you need Basics of python knowledge on Dictionary and functions knowledge on Classes and objects.        OK!! HERE IS THE CODE 😊                 import random import string     def create_shortURL(link):             chars = string.ascii_lowercase      # chars = ['a','c','z']      short_url = ''.join(random.choice(chars) for i in range ( 5 ))      d = {}      URL = 'https://www.plc.ly/' + short_url # PLC = Python Learn Camp             d[URL] = link            # This is optional        if URL in d:          print ( 'Your URL:' ,d[URL])          print ( 'Shorten URL:' ,URL) ...