COVID India live tracker with Python Flask

I know this is a really horrible situation in the world, at this moment I want to build COVID India live tracker with python flask.

Hello guys! Welcome to another exciting tutorial on COVID-19. I know this is a really horrible situation in the world, at this moment I want to build COVID India live tracker with python flask.

In recent days the python community builds a module for COVID India live data, which helps to get the live data of all states in India.

Installation

To use the COVID India python module, first, we need to install that python module. I give you the command to install.

pip install covid-india

If you want, you can check the documentation is here: Docs

Ok fine, let’s explore the COVID India python module.

from covid_india import states

print(states.getdata())

states.getdata():

It will return all state data in the format of JSON. Each state has Total, Death and Cured data. The output like below.

from covid_india import states

ap = states.getdata('Andhra Pradesh')
print(ap)

we can pass state parameter in states.getdata(state) method. It will return the state COVID data in the format JSON.

It is a JSON format, so we can access data through keys.

from covid_india import states

ap = states.getdata('Andhra Pradesh')

print('Total Covid Cases:',ap['Total'])

print('Cured Cases:',ap['Cured'])

print('Death Cases:',ap['Death'])

we can get any sates of COVID data if we pass the state parameter.

We can build a Flask or Django web app using python COVID India module data.

Flask deployment

Here, I used a flask to build a web app on COVID India data. If you don’t know the basics of Flask then please visit this

Flask Crash course tutorial for beginners

Alright! let’s build a python flask web app. Here I gave the code for COVID India live tracker.

app.py

from flask import Flask,request,render_template
from covid_india import states

app = Flask(__name__)

@app.route('/')
def home():
    state='Andhra Pradesh'
    data = states.getdata(state)
    return render_template('index.html',data=data,state=state)


if __name__== '__main__':
    app.run(debug=True)

index.html

Here we send the data to the template index.html. we use a template language to display the data. data is a JSON format data, so we can access the data using keys.

<!DOCTYPE html>
<html lang="en">

<head>
 <meta charset="UTF-8">    
 <meta name="viewport" content="width=device-width, initial-scale=1.0">    
 <title>APP</title>
</head>

<body>    

<div>
<h1>State: {{state}}</h1>

<h2>Total Cases:{{data['Total']}}</h2>

<h3>Cured: {{data['Cured']}}</h3>

<h4>Death: {{data['Death']}}</h4>

</div>

</body>

</html> 

In this way, we can add extra styles to the template and also we can build a search console to search different state’s data.

I build the complete web app using flask and deployed through Heroku. Here I gave the COVID India live tracker web app Link.

Kindly visit this link to view the complete project.

View project

If you want the full project code, Please check the link or Store.

Full project code: Link

If you love this tutorial please share in social media and if you have doubts , please comment below. To get more projects using python subscribe to our newsletter. Thank you!

1 thought on “COVID India live tracker with Python Flask”

Leave a Reply