aoc2020/scripts/countdown

35 lines
706 B
Plaintext
Raw Normal View History

2020-12-03 06:09:19 +00:00
#!/usr/bin/env bash
# 👆 hazel i hope you're happy
# challenges released in EST
export TZ="America/New_York"
function init_day {
2020-12-09 04:39:43 +00:00
day=$(($(date +%-d)))
2020-12-03 06:09:19 +00:00
if [ ! -f $day.rkt ]; then
2020-12-06 05:44:32 +00:00
set -m
scripts/get-challenge $day &
sleep 1
2020-12-03 06:09:19 +00:00
scripts/make-day $day
2020-12-06 05:44:32 +00:00
fg
2020-12-03 06:09:19 +00:00
return 1
fi
return 0
}
if init_day; then
2020-12-03 06:14:43 +00:00
next_day=$((day + 1))
2020-12-03 06:09:19 +00:00
next_timestamp=$(date --date="$(date +%Y-%m)-$next_day" +%s)
while true; do
2020-12-03 06:14:43 +00:00
secs_left=$((next_timestamp - $(date +%s)))
2020-12-03 06:09:19 +00:00
if [ $secs_left -le 0 ]; then
break
fi
printf "\r\x1b[K%s secs left..." "$secs_left"
2020-12-03 06:14:43 +00:00
sleep 0.3
2020-12-03 06:09:19 +00:00
done
printf "\r\x1b[K"
init_day
fi