summaryrefslogtreecommitdiff
path: root/.local/bin/qotd
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-08-28 00:42:40 +0300
committerThomas Voss <mail@thomasvoss.com> 2023-08-28 00:57:23 +0300
commit87a3773df52e73f755772f2cb109734e9c2158c9 (patch)
treeb43425d58e7b9610d09c451dbcfa19cfae93f849 /.local/bin/qotd
parent65bab05b45b0dd3b5f5629861ec44c24201f28e2 (diff)
qotd: Add quotes of the day
Diffstat (limited to '.local/bin/qotd')
-rwxr-xr-x.local/bin/qotd24
1 files changed, 24 insertions, 0 deletions
diff --git a/.local/bin/qotd b/.local/bin/qotd
new file mode 100755
index 0000000..3648072
--- /dev/null
+++ b/.local/bin/qotd
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+set -e
+
+readonly QUOTES="${XDG_DATA_HOME:-$HOME/.local/share}/romir/quotes.yml"
+readonly QOTD="${XDG_CACHE_HOME:-$HOME/.cache}/qotd"
+
+if [ ! -f "$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` ] \
+ && yq -0 '.mangoes.[].quote.content' <"$QUOTES" \
+ | shuf -zn1 \
+ | tr '\0' '\n' >"$QOTD"