Skip to content

Instantly share code, notes, and snippets.

@kyle-west
Last active March 11, 2020 14:32
Show Gist options
  • Select an option

  • Save kyle-west/e7939645f4bc49b0a9a4531928f13b52 to your computer and use it in GitHub Desktop.

Select an option

Save kyle-west/e7939645f4bc49b0a9a4531928f13b52 to your computer and use it in GitHub Desktop.
Get the latest stats on on the COVID-19 (Coronavirus) for your state on the command line (with notifications on Mac OSX)
#!/bin/bash
url='https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases/FeatureServer/1/query?f=json&where=(Confirmed%20%3E%200)%20AND%20(Country_Region%3D%27US%27)&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&orderByFields=Confirmed%20desc%2CCountry_Region%20asc%2CProvince_State%20asc&outSR=102100&resultOffset=0&resultRecordCount=250&cacheHint=true'
__getStats () {
json <(curl -s "$url") "
const data = \$.features.filter(x => x && x.attributes && x.attributes.Province_State && x.attributes.Province_State.includes && x.attributes.Province_State.includes('$1'))
const { Confirmed, Deaths, Recovered } = (data && data[0] && data[0].attributes) || {};
Confirmed && console.log('Confirmed: ' + Confirmed, 'Recovered: ' + Recovered, 'Deaths: ' + Deaths);
!Confirmed && console.log('No Data Found on $1')
"
}
if [ "$2" == "--watch" ]; then
while [ 1 ]; do
currentStats=`__getStats "$1"`
osascript -e "display notification \"$currentStats\" with title \"Latest COVID-19 $1 Stats\" subtitle \"$(date)\""
sleep 3600 # 1 hr
done
else
__getStats "$1"
fi
@kyle-west
Copy link
Author

kyle-west commented Mar 11, 2020

Screen Recording 2020-03-10 at 09 27 PM

Install

Installed with the bashful CLI.

bashful gist install https://gist.github.com/kyle-west/e7939645f4bc49b0a9a4531928f13b52

Usage

covid-19 takes a single argument for the state you want the get the latest stats on for the COVID-19 (Coronavirus).

Example

covid-19 California # --> Confirmed: 144 Recovered: 2 Deaths: 2

If you want a notification every hour on you Mac, run the following command in the background:

covid-19 <your state> --watch

Credits

The data for this script is collected from this dashboard from the Johns Hopkins University.

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