[download]

local/bin/daylight

   1 #!/bin/bash
   2 
   3 f=~/.cache/daylight
   4 
   5 if [[ $(date +%F) != $(date -r $f +%F) ]]; then
   6     IFS=, read dawn sunrise zenith sunset dusk < <(
   7     curl -s 'https://wttr.in/spb?lang=ru&format=%D,%S,%z,%s,%d')
   8 
   9     printf '%s %s\n' $dawn рассвет $sunrise восход \
  10     $zenith зенит $sunset заход $dusk сумерки > $f
  11 fi
  12 
  13 while read t s; do
  14     n=$(( $(date -d $t +%s) - $(date +%s) ))
  15     echo "$n ${t%:*} $s $(date -ud @${n#-} +'%_H %_M')" | awk '{
  16         n = ($4 ? $4 : $5 ) * ($1 < 0 ? -1 : 1)
  17         printf "%s  %+3d %s.  %s\n", $2, n, ($4 ? "ч" : "м"), $3
  18     }'
  19 done < $f