DEV Community

Cover image for Corona Tracker | Django Project |
Madhuban Khatri
Madhuban Khatri

Posted on

Corona Tracker | Django Project |

Hello Friends,
Do you also want to make your own website like Corona Tracker so that you can get updates of Corona sitting at home?
In this blog you will get the source code of Corona Tracker Project, with the help of which you can create your tracker.


from django.shortcuts import render
from django.http import HttpResponse

from bs4 import BeautifulSoup
import requests

url = ''

r = requests.get(url)
data = r.content
soup = BeautifulSoup(data, 'html.parser')

# Create your views here.
def index(request):
    active_cases = soup.find_all('div', {"class": "field-name-field-total-active-case"})
    cured_cases = soup.find_all('div', {"class": "field-name-field-total-cured-discharged"})
    death_cases = soup.find_all('div', {"class": "field-name-field-total-death-case"})

    state_lis = []
    confirmed = []
    cured = []
    deaths = []

    state_class = soup.find_all('div', {"class": "field-name-field-select-state"})
    confirmed_class = soup.find_all('div', {"class": "field-name-field-total-confirmed-indians"})
    cured_class = soup.find_all('div', {"class": "field-name-field-cured"})
    death_class = soup.find_all('div', {"class": "field-name-field-deaths"})

    for state in state_class:
    for confirm in confirmed_class:
    for cure in cured_class:
    for death in death_class:

    params = {"active_cases": active_cases[0].text[13:],
              "cured_cases": cured_cases[0].text[18:],
              "death_cases": death_cases[0].text[7:],
              "states": state_lis,
              "confirm": confirmed,"deaths": deaths, "cured": cured}
    return render(request, 'index.html', params)

Enter fullscreen mode Exit fullscreen mode

from django.urls import path
from . import views

urlpatterns = [
    path('', views.index, name='index')
Enter fullscreen mode Exit fullscreen mode


<!doctype html>
<html lang="en">
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap CSS -->
    <link href="" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">

    <title>Corona Tracker</title>
    <div class="container btn-primary w-50">
      <h2 style="transform: translate(30%, 0%)">Simple Corona Tracker</h2>
    <div class="container my-2 w-75">
      <div class="row">
        <div class="col">
          <h5>Active Cases: <span style="color: blue;">{{active_cases}}</span></h2>
        <div class="col">
          <h5>Cured Cases: <span style="color: green;">{{cured_cases}}</span></h2>
        <div class="col">
          <h5>Death Cases: <span style="color: red;">{{death_cases}}</span></h2>

    <div class="container border w-25" style="margin-left: 120px; display: inline-block;">
      {% for s in states %}
        <h6>{{s | truncatechars:27}}</h6>
      {% endfor %}

    <div class="container border w-25" style="display: inline-block;">
      <h4>TOTAL CONFRIMED</h4>
      {% for c in confirm %}
      {% endfor %}

    <div class="container border w-25" style="display: inline-block;">
      {% for cr in cured %}
      {% endfor %}

    <div class="container border" style=" display: inline-block; width: 200px;">
      {% for d in deaths %}
      {% endfor %}

    <!-- Option 1: Bootstrap Bundle with Popper -->
    <script src="" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)