dotfiles

regexghost dotfiles and scripts
git clone https://git.regexghost.com/dotfiles.git
Log | Files | Refs | README

metoffice.sh (1521B)


      1 #!/usr/bin/env bash
      2 
      3 # This script is quite ugly and needs re-writing, but it works for now
      4 
      5 [ -d "/tmp/panel_i3_data" ] || mkdir "/tmp/panel_i3_data"
      6 
      7 curLocationFile="$XDG_CONFIG_HOME/regexghost/current_location.csv"
      8 
      9 lat=$(cat "$curLocationFile" | cut -d "|" -f 1)
     10 lon=$(cat "$curLocationFile" | cut -d "|" -f 2)
     11 geohash=$(geohash $lat $lon 9)
     12 today_string="$(date "+%Y-%m-%d")"
     13 tomorrow_string="$(date -d $(($(date +%s)+86400)) "+%Y-%m-%d")"
     14 second_day_string="$(date -d $(($(date +%s)+86400+86400)) "+%Y-%m-%d")"
     15 
     16 curl --connect-timeout 5 -s -L "https://weather.metoffice.gov.uk/forecast/$geohash" > "/tmp/panel_i3_data/metoffice.html"
     17 # awk instead of grep -A/-B - https://superuser.com/questions/298123/how-to-grep-and-print-the-next-n-lines-after-the-hit/298127#298127
     18 icon_name_today=$(awk -v var="$today_string" '$0 ~ "datetime=\"" var "\"" {p = 5} p > 0 {print $0; p--}' "/tmp/panel_i3_data/metoffice.html" | grep "class=\"tab-icon\"" | sed 's/;" class.*//g' | sed 's/.*alt="//g')
     19 icon_name_tomorrow=$(awk -v var="$tomorrow_string" '$0 ~ "datetime=\"" var "\"" {p = 5} p > 0 {print $0; p--}' "/tmp/panel_i3_data/metoffice.html" | grep "class=\"tab-icon\"" | sed 's/;" class.*//g' | sed 's/.*alt="//g')
     20 icon_name_second_day=$(awk -v var="$second_day_string" '$0 ~ "datetime=\"" var "\"" {p = 5} p > 0 {print $0; p--}' "/tmp/panel_i3_data/metoffice.html" | grep "class=\"tab-icon\"" | sed 's/;" class.*//g' | sed 's/.*alt="//g')
     21 
     22 echo "$icon_name_today"
     23 echo "$icon_name_tomorrow"
     24 echo "$icon_name_second_day"
     25 
     26