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

Drawing A Design In Python

 Code :  from turtle import *  from random import randint  bgcolor('black')  x = 1  speed(0)  while x < 400:      r = randint(0,255)   g = randint(0,255)    b = randint(0,255)      colormode(255)    pencolor(r,g,b)   fd(50 + x)   rt(90.991)   x = x+1     exitonclick() Result : 

PIKACHU

CODE FOR DRAWING THIS PIKACHU IS BELOW: import turtle def getPosition(x, y): turtle.setx(x) turtle.sety(y) print(x, y) class Pikachu: def __init__(self): self.t = turtle.Turtle() t = self.t t.pensize(3) t.speed(9) t.ondrag(getPosition) def noTrace_goto(self, x, y): self.t.penup() self.t.goto(x, y) self.t.pendown() def leftEye(self, x, y): self.noTrace_goto(x, y) t = self.t t.seth(0) t.fillcolor('#333333') t.begin_fill() t.circle(22) t.end_fill() self.noTrace_goto(x, y+10) t.fillcolor('#000000') t.begin_fill() t.circle(10) t.end_fill() self.noTrace_goto(x+6, y + 22) t.fillcolor('#ffffff') t.begin_fill() t.circle(10) t.end_fill() def rightEye(self, x, y): self.noTrace_goto(x, y) t = self.t ...

Drawing Doraemon

CODE:  from turtle import * def my_goto(x, y): penup() goto(x, y) pendown() def eyes(): fillcolor("#ffffff") begin_fill() tracer(False) a = 2.5 for i in range(120): if 0 <= i < 30 or 60 <= i < 90: a -= 0.05 lt(3) fd(a) else: a += 0.05 lt(3) fd(a) tracer(True) end_fill() def beard(): my_goto(-32, 135) seth(165) fd(60) my_goto(-32, 125) seth(180) fd(60) my_goto(-32, 115) seth(193) fd(60) my_goto(37, 135) seth(15) fd(60) my_goto(37, 125) seth(0) fd(60) my_goto(37, 115) seth(-13) fd(60) def mouth(): my_goto(5, 148) seth(270) fd(100) seth(0) circle(120, 50) seth(230) circle(-120, 100) def scarf(): fillcolor('#e70010') begin_fill() seth(0) fd(200) circle(-5, 90) fd(10) circle(-5, 90) fd(20...