Created
March 27, 2020 17:18
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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