Skip to content

Instantly share code, notes, and snippets.

@meleu
Created March 27, 2020 17:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meleu/75f463d8283891158905ab9cd9437988 to your computer and use it in GitHub Desktop.
Save meleu/75f463d8283891158905ab9cd9437988 to your computer and use it in GitHub Desktop.
Show a bargraph with a ranking of countries with the highest number of deaths caused by COVID-19
#!/usr/bin/env bash
# covid-ranking.sh
##################
#
# Show a bargraph with a ranking of countries with
# the highest number of deaths caused by COVID-19.
#
# Dependencies: curl, jq, termgraph
#
# (install termgraph via `pip3 install termgraph`)
readonly URL='https://corona.lmao.ninja/countries?sort=deaths'
readonly DEPENDENCIES=(curl jq termgraph)
checkDependencies() {
local errorFound=0
for command in "${DEPENDENCIES[@]}"; do
if ! which "$command" > /dev/null ; then
echo "ERROR: command not found: '$command'" >&2
errorFound=1
fi
done
if [[ "$errorFound" != "0" ]]; then
echo "---ABORTING---"
echo "This scripts needs the commands listed above." >&2
echo "Install them and/or check if they're in your \$PATH" >&2
exit 1
fi
}
main() {
checkDependencies
curl --silent "$URL" \
| jq '.[:10][] | "\(.country);\(.deaths)"' \
| tr -d \" \
| termgraph --delim ';' --title 'Countries with the highest number of deaths caused by COVID-19' \
| sed 's/\.00$//'
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment