Get Current COVID cases data using python

To get Current COVID cases WorldWide

  • In the first step you need to install the library Covid using below command in terminal
    pip install Covid
  • Note that your file name should not be a covid.py or Covid.py
  • In the below code, covid = Covid() is used in order to make a code simpler where covid is a variable initialised by Covid() module.
#COVID cases WorldWide

from covid import Covid

covid = Covid()


def covid_worlwide():
    print("Active cases : ", covid.get_total_active_cases())
    print("Confirmed cases : ", covid.get_total_confirmed_cases())
    print("Total Recovered : ", covid.get_total_recovered())
    print("Total Deaths : ", covid.get_total_deaths())


covid_worldwide()
# COVID cases for specified Country

from covid import Covid

covid = Covid()
india = covid.get_status_by_country_name('india')
data = {                                              #using dictionary in order to get required data only
    key: india[key]
    for key in india.keys() and {'confirmed','active','deaths','recovered'}
}

print(data)

To get Current COVID cases in INDIA

  • Here also you need to install a library called covid-india using a below command in terminal
pip install covid-india
# For all state details

from covid_india import states
print(states.getdata())
# For specific state details

from covid_india import states
print(states.getdata('Karnataka'))
  • Note that state name should begin with capital letter for each word
  • e.g : 'Karnataka', 'West Bengal', 'Jammu and Kashmir' and so on.....

 ^-^ Stay home Stay safe  ^-^

Posted on by