summary refs log tree commit diff
path: root/booktime
blob: 2b4f2be9e3305b38bb20ea79446450644687b4a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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