(Demo) How to Read Up-to-Date COVID-19 Data in Python 3 (Updated)


GeeXLab demo - How to Read Up-to-Date COVID-19 Data in Python 3



Downloads

 
If you wonder how to access to up-to-date data about new Coronavirus (COVID-19 or better, SARS-CoV-2 which is the official codename) cases, I found this simple to use Python package: COVID19Py (the github repository is available HERE).

To install it, run the following command in a terminal (the pip executable must be in the bin search path):

pip install COVID19Py

 
Alternatively, you can open a terminal in the C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\Scripts\ folder where the pip executable is stored.

Once installed, this tiny lib is really easy to use. The following code snippet shows how to read all important data in few Python lines:

import COVID19Py
 
covid19_jhu = COVID19Py.COVID19(data_source="jhu")
latest_jhu = covid19_jhu.getLatest()
locations_ALL = covid19_jhu.getLocations(rank_by='confirmed')

 
The COVID-19 cases data is read from the Johns Hopkins University Center for Systems Science and Engineering (JHU CSSE).

getLatest() returns the following dictionary:

{
'confirmed': 1511104, 
'deaths': 88338, 
'recovered': 0
}

 
getLocations() returns a big list of dictionaries, one dictionary for each location. Currently, 263 locations are returned by getLocations().

Here is the first entry (a dictionary) of the location list (I sorted by confirmed cases, that’s why the US are in top position…):

{
'id': 225, 
'country': 'US', 
'country_code': 'US', 
'country_population': 310232863, 
'province': '', 
'last_updated': '2020-04-09T16:25:21.803522Z', 
'coordinates': {'latitude': '37.0902', 'longitude': '-95.7129'}, 
'latest': {'confirmed': 429052, 'deaths': 14695, 'recovered': 0}
}

 
I coded a demo with GeeXLab that displays all COVID-19 cases data by location. COVID-19 confirmed cases can be visualized in 2D or 3D.

The demo requires the latest GeeXLab 0.30.0 (few bugs have been fixed in the gh_imgui library in the Python plugin).

Download the Python 3 demopack and load the geexlab-demopack-python3/general/03-covid19/main.xml demo in GeeXLab. GeeXLab 0.30+ for Windows comes with the COVID19Py package so you can directly run the demo.

2D view:
GeeXLab demo - How to Read Up-to-Date COVID-19 Data in Python 3

 
3D view:
GeeXLab demo - How to Read Up-to-Date COVID-19 Data in Python 3

 
This demo can be improved by storing COVID-19 data in a SQLite3 database and doing some interesting stats (like changes between days).

 

Update (2020.04.12): 2D mode: XBar and YBar

YBar:
GeeXLab demo - How to Read Up-to-Date COVID-19 Data in Python 3

XBar:
GeeXLab demo - How to Read Up-to-Date COVID-19 Data in Python 3

 

Update (2020.04.17): 2D mode: YBar with ImGui

YBar using ImGui progress bar
gh_imgui.progress_bar() function is used to represent confirmed cases. This solution is simpler to code because text alignment on the progress bar is handled by ImGui.

GeeXLab demo - How to Read Up-to-Date COVID-19 Data in Python 3





Leave a Comment

Your email address will not be published. Required fields are marked *