diff options
author | Thomas Voss <mail@thomasvoss.com> | 2023-09-02 18:58:35 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2023-09-02 18:58:35 +0200 |
commit | 59fd62163f9f249093dd0bf1d04835fec15e25d6 (patch) | |
tree | f909f26f0443683a66f3f79351fd3cdd53118249 /.local | |
parent | b8316dc0f355ccf87b9c6761578a5a071af865dd (diff) |
qotd: Fix bugs and optimize behavior
Diffstat (limited to '.local')
-rwxr-xr-x | .local/bin/qotd | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/.local/bin/qotd b/.local/bin/qotd index 3648072..ec1eb20 100755 --- a/.local/bin/qotd +++ b/.local/bin/qotd @@ -2,23 +2,31 @@ set -e +older_than_today() +{ + if [ ! -f "$1" ] + then + mod=0000-00-00 + else + mod=`stat -c %y "$1" | xargs -I{} -- date -d{} +%F` + fi + + [ $mod != `date +%F` ] + return $? +} + readonly QUOTES="${XDG_DATA_HOME:-$HOME/.local/share}/romir/quotes.yml" readonly QOTD="${XDG_CACHE_HOME:-$HOME/.cache}/qotd" -if [ ! -f "$QUOTES" ] +if older_than_today "$QUOTES" then dirname "$QUOTES" | xargs mkdir -p chronic wget 'https://romir.eu/mangoes.yaml' -O "$QUOTES" fi -if [ ! -f "$QOTD" ] -then - mod=0000-00-00 -else - mod=`stat -c %y "$QOTD" | xargs -I{} -- date -d{} +%F` -fi - -[ $mod != `date +%F` ] \ +older_than_today "$QOTD" \ && yq -0 '.mangoes.[].quote.content' <"$QUOTES" \ | shuf -zn1 \ | tr '\0' '\n' >"$QOTD" + +exit 0 |