Open rsubtil opened 3 years ago
For anyone interested in this functionality, I've developed a script to do this: (change the top variables to your liking and setup)
#!/bin/sh
maxTime=14400 # 14400 seconds = 4 hours; change this to your desired value
dateFormat="%Hh%Mm%Ss" # Format string to format the remaining time before updating, parsed by `date`
tempFile=/tmp/covidStatus # Path for the locally cached statistics
command="corona-cli portugal -m" # How you run the `corona-cli` command
if [ ! -f $tempFile ]; then
echo "COVID-19 Statistics: (no cached results; updating...)"
$command > $tempFile
else
timeCreated=$(date --utc --reference=$tempFile +%s)
timeNow=$(date --utc +%s)
delta=$(($timeNow-$timeCreated))
if [ $delta -gt $maxTime ]; then
echo "COVID-19 Statistics: (cached results too old; updating...)"
$command > $tempFile
else
echo "COVID-19 Statistics: (cached results; will update again in $(date --utc --date="@$(($maxTime-$delta))" +$dateFormat))"
fi
fi
It would still be cool if this was properly implemented in the program, but for now, it does the job :stuck_out_tongue:
This is a very interesting project, especially for displaying everyday statistics on terminal initialization by adding it to
.bashrc
.However, the program always fetches the data online; thus it always takes some time to load. It would be cool if the program only fetched the current day's statistics and cache them locally: this way, any subsequent calls would run considerably faster (and as far as I know, most countries only update their statistics daily anyway).