[download]

local/bin/moonday

   1 #!/bin/bash
   2 
   3 f=~/.cache/${0##*/}
   4 
   5 [[ -s $f ]] && (( $(date +%s) - $(date +%s -r $f) < 60 * 60 )) || { # {{{
   6     torsocks curl -sf \
   7     https://mirkosmosa.ru/lunar-calendar/phase-moon/lunar-day-today \
   8     https://mirkosmosa.ru/lunar-calendar/phase-moon/$(LANG= date +%Y/%B) > $f.html
   9 
  10     {
  11         grep -o 'curr_date.*' $f.html | grep -o '<img class="moon-i"[^>]*>' |
  12         sed 's/[^0-9]*//g; 1q'
  13 
  14         grep -A 1 phase_data $f.html | awk -F '  +' '/<\/div>/ { print $2 }'
  15         grep -A 1 illum      $f.html | awk          '/<\/div>/ { print $2 }'
  16 
  17         grep -o 'moon_desc_default[^>]*[^<]*' $f.html | tac |
  18         awk -F \> '{ print $2 }' | sed 's/\(:[0-9]*\).*/\1/; s/[0-9]*/\0-й/; 1q'
  19 
  20         paste -d ' ' \
  21         <(grep -o 'next_phase_after[^<]*'       $f.html | awk -F '[<>]' '{ print $2 }') \
  22         <(grep -o 'next_phase_name[^<]*><[^<]*' $f.html | awk -F '[<>]' '{ print $4 }')
  23 
  24     } > $f
  25 } # }}}
  26 
  27 IFS=$'\n' read -d '' icon moonphase moonlight moonday nextphase{1..4} _ < $f
  28 moonphase=${moonphase,,}
  29 
  30 echo "${moonphase^}"
  31 echo
  32 echo "Видимость $moonlight"
  33 echo
  34 echo "$moonday"
  35 echo
  36 
  37 for i in {1..4}; do
  38     i=nextphase$i
  39     i=${!i}
  40     z=${i##* }
  41     i=${i% *}
  42     y=${i##* }
  43     i=${i% *}
  44     echo "$y ${z,,} $i"
  45 done