Skip to content

Instantly share code, notes, and snippets.

@yitsushi
Created March 24, 2020 12:00
Show Gist options
  • Save yitsushi/94b2c60b7b3f2842015e316ded77cac4 to your computer and use it in GitHub Desktop.
Save yitsushi/94b2c60b7b3f2842015e316ded77cac4 to your computer and use it in GitHub Desktop.
covid-19 tracker
import requests
import sys
def check(name, row):
if name is None:
return True
if name == row['country'].lower():
return True
if name == row['countryInfo']['iso2'].lower():
return True
return False
res = requests.get('https://corona.lmao.ninja/countries').json()
labels = ['Name', 'Cases', 'Deaths',
'Recovered', 'Active', 'Critical',
'Cases / One Million']
print('{0:25s} | {1:14s} | {2:13s} |'
' {3:10s} | {4:8s} | {5:8s} | {6:19s} |'.format(*labels))
print('-'*117)
name = None
if len(sys.argv) > 1:
name = sys.argv[1].lower()
for row in res:
if check(name, row):
print('{country:25s} | {cases:6d} (+{todayCases:<4d}) |'
' {deaths:5d} (+{todayDeaths:<4d}) |'
' {recovered:10d} | {active:8d} | {critical:8d} |'
' {casesPerOneMillion:19d} |'.format(**row))
@yitsushi
Copy link
Author

❯ python ~/covid-19.py hu
Name                      | Cases          | Deaths        | Recovered  | Active   | Critical | Cases / One Million |
---------------------------------------------------------------------------------------------------------------------
Hungary                   |    187 (+20  ) |     9 (+1   ) |         21 |      157 |        6 |                  19 |

❯ python ~/covid-19.py uk
Name                      | Cases          | Deaths        | Recovered  | Active   | Critical | Cases / One Million |
---------------------------------------------------------------------------------------------------------------------
UK                        |   6650 (+0   ) |   335 (+0   ) |        135 |     6180 |       20 |                  98 |

❯ python ~/covid-19.py | head -n 10
Name                      | Cases          | Deaths        | Recovered  | Active   | Critical | Cases / One Million |
---------------------------------------------------------------------------------------------------------------------
China                     |  81171 (+78  ) |  3277 (+7   ) |      73159 |     4735 |     1573 |                  56 |
Italy                     |  63927 (+0   ) |  6077 (+0   ) |       7432 |    50418 |     3204 |                1057 |
USA                       |  46168 (+2434) |   582 (+29  ) |        295 |    45291 |     1040 |                 139 |
Spain                     |  39673 (+4537) |  2696 (+385 ) |       3794 |    33183 |     2355 |                 849 |
Germany                   |  30150 (+1094) |   130 (+7   ) |        453 |    29567 |       23 |                 360 |
Iran                      |  24811 (+1762) |  1934 (+122 ) |       8913 |    13964 |        0 |                 295 |
France                    |  19856 (+0   ) |   860 (+0   ) |       2200 |    16796 |     2082 |                 304 |
Switzerland               |   9117 (+322 ) |   122 (+2   ) |        131 |     8864 |      141 |                1053 |
# [cut]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment