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