scripts

scripts to make my pc work
Index Commits Files Refs
statusbar/sb-weather (938B)
   1 #!/bin/sh
   2 
   3 nc -dzw2 google.com 443 2> /dev/null
   4 
   5 if [[ $? -ne 0 ]]; then
   6     printf "☠️ Service down\n" ;
   7     exit;
   8 fi
   9 
  10 # $(nc -dzw2 google.com 443 &> /dev/null) || printf "☠️ Service down\n"  && exit 0
  11 
  12 curr_time=$(date +"%H%M")
  13 raw=$(curl -s wttr.in/1876\?format="%d|%S|%t|%C|%c|%m\n" | tr --delete " " | cut -d "|" -f 1,2,3,4,5,6)
  14 
  15 echo $raw | grep -i unknown -q && printf "☠️ Service down" && exit
  16 
  17 for i in {0..5}; do
  18     data[$i]=$(echo -n $raw | cut -d "|" -f $((i + 1)))
  19 done
  20 
  21 data[2]=$(echo -n ${data[2]} | cut -d "," -f 1)
  22 
  23 dusk=$(echo -n ${data[0]} | cut -d ":" -f 1,2 | tr --delete ":")
  24 sunrise=$(echo -n ${data[1]} | cut -d ":" -f 1,2 | tr --delete ":")
  25 temp=$(echo -n ${data[2]})
  26 condition=${data[3]}
  27 day=${data[4]}
  28 moon=${data[5]}
  29 temp=$(echo -n ${data[2]} | tr --delete '+')
  30 
  31 [[ $curr_time -lt $dusk && $curr_time -gt $sunrise ]] &&
  32     printf "%s %s %s" $day $condition $temp ||
  33     printf "%s %s %s" $moon $condition $temp