diff options
author | noa | 2024-01-03 10:25:33 +0000 |
---|---|---|
committer | noa | 2024-01-03 10:25:33 +0000 |
commit | 7f9c6a9a437323731261589f8e890e742b36e71a (patch) | |
tree | b370494e9af70d374aad4782f90f9f66aee6d772 | |
parent | 50556112d256e05ccc869044a2cb1b857abc296b (diff) |
Add booktime command.
Booktime gets the calling user's current time and prints a quote that features that time.
-rwxr-xr-x | booktime | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/booktime b/booktime new file mode 100755 index 0000000..2b4f2be --- /dev/null +++ b/booktime @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +# inspired by and using data from https://literature-clock.jenevoldsen.com/ + +# $2 = noa!noa@localhost +NICK="${2%!*}" +[ -z "$NICK" ] && NICK="$(whoami)" + +# the following timezone logic is taken from /town/our/timefor <3 +ip=$(finger $NICK 2>/dev/null | egrep -o -m 1 '([0-9]{1,3}\.){3}[0-9]{1,3}') +[[ -z $ip ]] && ip=$(finger $1 2>/dev/null | egrep -o -i -m 1 '([0-9a-f]){1,4}(:([0-9a-f]){1,4}){1,7}') +[[ -n $ip ]] && TIMEZONE=$(curl -s "https://ipapi.co/$ip/timezone") + +TIME=$(TZ=$TIMEZONE date "+%H:%M") +SENTS="/home/noa/doc/booktime.psv" + +awk -F '|' -v time="$TIME" \ + '{ if ($1 == time) { print $3 " --" $5 ", " $4 } else {next }}' "$SENTS" \ + | shuf \ + | tail -n1 + |