Covid Live Report Using Raspberry Pi

16601

Intro: Covid Live Report Using Raspberry Pi

As we know the whole world is being affected by 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 corona virus cases in India. This Python script fetches the live data from Ministry of Health Affairs Official Website.

STEP 1: Raspberry Pi Setup

Make Sure the OS Is Installed on the SD Card. Your SD might have Raspberry Pi Operating System installed. ...Configure the Wifi Connection on Your SD Card. ...Turn on Your Raspberry Pi. ...Connect to Your Raspberry Pi with SSH. ...Install VNC Server. ...Install a VNC Viewer on Your Laptop.

To run a program

Before we start writing the software we first need to install the Raspberry Pi GPIO Python module. This is a library that allows us to access the GPIO port directly from Python.

To install the Python library open a terminal and execute the following

pip install python-rpi.gpio python3-rpi.gpio

With the library installed now open your favorite Python IDE and paste this code or try yourself

STEP 2: You Need to Install Some Additional Features for It They Are:-

pip install bs4

pip install tabulate

pip install matplotlib

pip install numpy

you need to open command prompt, to go search button and enter cmd and open with Run as administrator


STEP 3: Importing Libaray

# importing libraries

import requests

from bs4 import BeautifulSoup

from tabulate import tabulate

import os

import numpy as np

import matplotlib.pyplot as plt

STEP 4: Collecting Live Data From Ministry of Health Affairs Official Website.

extract_contents = lambda row: [x.text.replace('\n', '') for x in row]

URL = 'https://www.mohfw.gov.in/' SHORT_HEADERS = ['SNo', 'State','Indian-Confirmed', '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) == 5:

# last row

stat = ['', *stat]

stats.append(stat)

elif len(stat) == 6:

stats.append(stat)

stats[-1][1] = "Total Cases"

stats.remove(stats[-1])

STEP 5: Creating Table to Show the Output

objects = []

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

y_pos = np.arange(len(objects))

performance = []

for row in stats :

performance.append(int(row[2]) + int(row[3]))

table = tabulate(stats, headers=SHORT_HEADERS)

print(table)

STEP 6: Now You Can See That Report

Remember it is live report so there is change in every time

Comments