108 lines
2.3 KiB
Bash
Executable File
108 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
ex(){
|
|
echo -e "\\033[0;32m> ${*} \\033[0m"
|
|
$@
|
|
}
|
|
date=$(date +"%Y-%m-%d")
|
|
ydate=$(date -d yesterday +"%Y-%m-%d")
|
|
show(){
|
|
echo -e "\\033[1;36m> ${*} \\033[0m"
|
|
}
|
|
|
|
data="$HOME/Documents/cv"
|
|
|
|
if [ ! -d "$data" ]
|
|
then
|
|
ex "mkdir -p $data"
|
|
# This is just for migration. Remove afterwards.
|
|
ex "mv /tmp/cv/* $data/ -v"
|
|
fi
|
|
|
|
# If not set by an environment variable, set country to $1.
|
|
if [ -z "$country" ]
|
|
then
|
|
country=$1
|
|
fi
|
|
|
|
get(){
|
|
if [ -f "$data/$date-$country" ]
|
|
then
|
|
jq -r ".$1" < "$data/$date-$country"
|
|
else
|
|
curl -sL corona.lmao.ninja/v2/"$endpoint" > "$data/$date-$country"
|
|
jq -r ".$1" < "$data/$date-$country"
|
|
fi
|
|
}
|
|
yget(){
|
|
date=$ydate
|
|
get "$1"
|
|
}
|
|
out(){
|
|
w=10
|
|
if [ -z $3 ]
|
|
then
|
|
printf "║ %-${w}s ║ %-${w}s ║ %-${w}s ║\n" "$1:" "$(get $2)" "+ $(expr $(get $2) - $(yget $2))"
|
|
else
|
|
printf "%-${w}s %d\n" "$1:" "$(yget $2)"
|
|
fi
|
|
}
|
|
frame(){
|
|
case "$1" in
|
|
up) printf "╔════════════╦════════════╦════════════╗\n" ;;
|
|
down) printf "╚════════════╩════════════╩════════════╝\n" ;;
|
|
esac
|
|
}
|
|
result(){
|
|
frame up
|
|
out Total cases
|
|
out Active active
|
|
out Critical critical
|
|
out New todayCases
|
|
out Deaths deaths
|
|
out Recovered recovered
|
|
out Tests tests
|
|
frame down
|
|
if [ -f "$data/$ydate-$country" ]
|
|
then
|
|
if [ "$(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 -rp "Answer (y/n): " answer
|
|
if [ "$answer" == "y" ]
|
|
then
|
|
ex "rm $data/$date-$country"
|
|
fi
|
|
fi
|
|
else
|
|
show "Yesterday's data file for this country doesn't exist."
|
|
fi
|
|
if [ "$(get todayCases)" == "0" ]
|
|
then
|
|
show "Seems like the cases today are not yet updated."
|
|
show "The data file will be removed. Please try again later."
|
|
ex "rm $data/$date-$country"
|
|
fi
|
|
}
|
|
|
|
show "Queried at: $date"
|
|
if [ ! -z "$country" ]
|
|
then
|
|
if [ "$country" == "all" ]
|
|
then
|
|
endpoint=all
|
|
result
|
|
else
|
|
endpoint=countries/$country
|
|
result
|
|
fi
|
|
else
|
|
# Change this to your own country as desired.
|
|
country=Belgium
|
|
show "Country has been set to $country."
|
|
endpoint=countries/$country
|
|
result
|
|
fi
|