How to get COVID 19 update using Covid module in Python?

A new Python library which tells the COVID-19 related information (country-wise) and it show that how many cases of confirmed, active, deaths, recovered found in that particular Country.

Requirement:
You have python package named COVID and python >= 3.6

Installation:

pip install covid

Dependencies:

  • pydantic
  • requests

Example:



filter_none

edit
close

play_arrow

link
brightness_4
code

from covid import Covid
  
  
covid = Covid()
india = covid.get_status_by_country_name("india")
  
data ={
    key:india[key]
    for key in india.keys() and {'confirmed'
                                 'active',
                                 'deaths',
                                 'recovered'}
}
  
print(data)

chevron_right


Output:

{‘confirmed’: 119419, ‘active’: 66863, ‘recovered’: 48957, ‘deaths’: 3599}

Let’s look at the modules basic functionality –

  • List Countries and their Id’s: This comes in need when you need to know the names of countries while using get_status_by_country_name, eg to use ‘America’ or ‘United States of America’ or ‘US’
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    from covid import Covid
      
    covid = Covid()
    countries = covid.list_countries()
      
    print(countries)

    chevron_right

    
    

    Output:

    [{‘id’: ’18’, ‘name’: ‘US’}, {‘id’: ’14’, ‘name’: ‘Russia’}, {‘id’: ’22’, ‘name’: ‘Brazil’}, {‘id’: ’17’, ‘name’: ‘United Kingdom’}, {‘id’: ’19’, ‘name’: ‘Spain’}, {‘id’: ’11’, ‘name’: ‘Italy’}, {‘id’: ‘7’, ‘name’: ‘France’}, {‘id’: ‘8’, ‘name’: ‘Germany’}, {‘id’: ‘176’, ‘name’: ‘Turkey’}, {‘id’: ’93’, ‘name’: ‘Iran’}, {‘id’: ’91’, ‘name’: ‘India’}, {‘id’: ‘141’, ‘name’: ‘Peru’}, {‘id’: ‘4’, ‘name’: ‘China’}, {‘id’: ‘3’, ‘name’: ‘Canada’}, {‘id’: ‘153’, ‘name’: ‘Saudi Arabia’}, {‘id’: ’20’, ‘name’: ‘Mexico’},

    Note: The list is too long, the above output is just a part of the list.

  • Get Data: To get COVID-19 related information.
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    from covid import Covid
      
      
    covid = Covid()
    print(covid.get_data())

    chevron_right

    
    

    Output:

    [{‘id’: ’18’, ‘country’: ‘US’, ‘confirmed’: 1577758, ‘active’: 1181132, ‘deaths’: 94729, ‘recovered’: 298418, ‘latitude’: 40.0, ‘longitude’: -100.0, ‘last_update’: 1590143562000}, {‘id’: ’14’, ‘country’: ‘Russia’, ‘confirmed’: 326448, ‘active’: 223374, ‘deaths’: 3249, ‘recovered’: 99825, ‘latitude’: 61.524, ‘longitude’: 105.3188, ‘last_update’: 1590143562000},



    Note: The list is too long, the above output is just a part of the list.

  • Get Status By Country ID: To get COVID-19 related information by Country Id
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    from covid import Covid
      
    covid = Covid()
    cases = covid.get_status_by_country_id(18)
      
    print(cases)

    chevron_right

    
    

    Output:

    {‘id’: ’18’, ‘country’: ‘US’, ‘confirmed’: 1541110, ‘active’: 1154535, ‘deaths’: 92712, ‘recovered’: 289392, ‘latitude’: 40.0, ‘longitude’: -100.0, ‘last_update’: 1590003166000}

  • Get Status By Country Name
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    from covid import Covid
      
    covid = Covid()
    italy_cases = covid.get_status_by_country_name("italy")
      
    print(italy_cases)

    chevron_right

    
    

    Output:

    {‘id’: ’11’, ‘country’: ‘Italy’, ‘confirmed’: 227364, ‘active’: 62752, ‘deaths’: 32330, ‘recovered’: 132282, ‘latitude’: 41.8719, ‘longitude’: 12.5674, ‘last_update’: 1590003166000}

  • Get Total Confirmed cases, Active cases, Recovered cases and Deaths
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    from covid import Covid
      
      
    covid = Covid()
      
    confirmed = covid.get_total_confirmed_cases()
    print('Confirmed :', end =" ")
    print(confirmed)
      
    active = covid.get_total_active_cases()
    print("Active:", end =" ")
    print(active)
      
    recovered = covid.get_total_recovered()
    print('Recovered:', end =" ")
    print(recovered)
      
    deaths = covid.get_total_deaths()
    print('Deaths:', end =" ")
    print(deaths)

    chevron_right

    
    

    Output:

    Confirmed : 4955312
    Active: 2750033
    Recovered: 1874998
    Deaths: 325810

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.