Lint and improve cv with shellcheck

This commit is contained in:
Michael De Roover 2020-05-12 15:17:36 +02:00
parent 62179f5ad3
commit 9fb4a3dc14
Signed by: vim
GPG Key ID: 075496E232CE04CB

26
cv
View File

@ -8,13 +8,13 @@ else
date=$(date +"%Y-%m-%d") date=$(date +"%Y-%m-%d")
ydate=$(date -d yesterday +"%Y-%m-%d") ydate=$(date -d yesterday +"%Y-%m-%d")
show(){ show(){
echo -e "\033[1;36m> ${@} \033[0m" echo -e "\\033[1;36m> ${*} \\033[0m"
} }
fi fi
data="$HOME/Documents/cv" data="$HOME/Documents/cv"
if [ ! -d $data ] if [ ! -d "$data" ]
then then
ex "mkdir $data" ex "mkdir $data"
# This is just for migration. Remove afterwards. # This is just for migration. Remove afterwards.
@ -22,44 +22,44 @@ then
fi fi
# If not set by an environment variable, set country to $1. # If not set by an environment variable, set country to $1.
if [ -z $country ] if [ -z "$country" ]
then then
country=$1 country=$1
fi fi
get(){ get(){
if [ -f $data/$date-$country ] if [ -f "$data/$date-$country" ]
then then
cat $data/$date-$country | jq -r .$1 jq -r ".$1" < "$data/$date-$country"
else else
curl -sL corona.lmao.ninja/v2/$endpoint > $data/$date-$country curl -sL corona.lmao.ninja/v2/"$endpoint" > "$data/$date-$country"
cat $data/$date-$country | jq -r .$1 jq -r ".$1" < "$data/$date-$country"
fi fi
} }
yget(){ yget(){
date=$ydate date=$ydate
get $1 get "$1"
} }
result(){ result(){
echo "Total: $(get cases)" echo "Total: $(get cases)"
echo "Active: $(get active)" echo "Active: $(get active)"
echo "New: $(get todayCases)" echo "New: $(get todayCases)"
echo "Tests: $(get tests)" echo "Tests: $(get tests)"
if [ -f $data/$ydate-$country ] if [ -f "$data/$ydate-$country" ]
then then
show "Yesterday's stats:" show "Yesterday's stats:"
echo "New: $(yget todayCases)" echo "New: $(yget todayCases)"
if [ $(get todayCases) == "0" ] if [ "$(get todayCases)" == "0" ]
then then
show "Seems like the cases today are not yet updated." show "Seems like the cases today are not yet updated."
show "The data file will be removed. Please query again later." show "The data file will be removed. Please query again later."
ex "rm $data/$date-$country" ex "rm $data/$date-$country"
elif [ $(get todayCases) == $(yget todayCases) ] elif [ "$(get todayCases)" == "$(yget todayCases)" ]
then then
show "Seems like the stats are the same as yesterday." show "Seems like the stats are the same as yesterday."
show "This could be normal but may mean that the data file is still yesterday's." show "This could be normal but may mean that the data file is still yesterday's."
show "Do you want to remove it?" show "Do you want to remove it?"
read -p "Answer (y/n): " answer read -rp "Answer (y/n): " answer
if [ "$answer" == "y" ] if [ "$answer" == "y" ]
then then
ex "rm $data/$date-$country" ex "rm $data/$date-$country"
@ -71,7 +71,7 @@ result(){
} }
show "Queried at: $date" show "Queried at: $date"
if [ ! -z $country ] if [ ! -z "$country" ]
then then
if [ "$country" == "all" ] if [ "$country" == "all" ]
then then