Mint Serena 64 bit using the Mate desktop environment. Most of the following scripts will run on this machine, although some have only been tested with the Gnome desktop. Extra software requirements can be met by the Ubuntu and safe PPA repositories. Scripts may be re-written or added to from time to time, the date serves as the version number. Syntax highlighting on these pages is provided by GVim's "Convert to HTML" option.
Showing posts with label weather. Show all posts
Showing posts with label weather. Show all posts

Weather Scraper


#!/bin/bash
# Filename: weather.sh
# Version.: 21092018
# Author..: robz
#
# Met Office scraper widget.
# Get the url from the web page for your location, chop the date off the end.
# Run from a launcher with this command.
# mate-terminal -t "Current Weather" -e /home/robz/scripts/weather.sh
#
sed1 () { sed 's/<[^>]\+>//g'; }
sed2 () { sed -e 's/^[ \t\n]*//;s/[ \t\n]*//'; }

wsite="https://www.metoffice.gov.uk/public/weather/forecast/qwerty123#?date="
wfile="/home/robz/scripts/weather.txt"
hours=$(date +%H | sed 's/^0//')
today="$(date +%Y-%m-%d)"
check=$(grep 'Timecheck' "$0" | tail -1 | cut -d' ' -f3)

if [[ "$check" != "$hours" ]]; then             # Check stamp at end of script.
    wget -q --retry-connrefused --waitretry=1 \
    "$wsite$today" -O "$wfile"                  # If it's old re-scrape page.
    sed -i '$d' "$0"                            # Delete old time stamp.
    echo "# Timecheck $hours" >> $0             # Insert new.
fi

echo -e "\nTodays weather - $(date +%a' '%d' '%b' - '%H':00') onwards:-\n"

time=$(grep -m1 -A9 'Now' "$wfile" | sed1 | sed2)
aspt=$(grep -m1 -A30 'weatherWX' "$wfile" | sed2 | grep 'title' | \
cut -d\" -f2 | sed -e 's/day\|night//')
prec=$(grep -m1 -A10 'Chance' "$wfile" | sed1 | sed2 | cut -d\; -f2 | tail)
temp=$(grep -m1 -A80 'weatherTemp' "$wfile" | grep 'data-value=' | \
cut -d\" -f2 | sed 's/$/°C/')
wind=$(grep -m10 -A10 '"direction"' "$wfile" | grep 'data-value=' | \
cut -d\" -f2 | sed -e 's/$/mph/')
win2=$(grep -m10 -A10 '"direction"' "$wfile" | grep 'data-value2=' | \
cut -d\" -f2)
gust=$(grep -m11 -A11 '"gust"' "$wfile" | grep 'data-value="' | sed 'n;d;' | \
cut -d\" -f2 | sed -e 's/$/mph/')

hours=$(( 24-hours ))                           # Number of hours to head file.
paste <(echo "$time") <(echo "$aspt") <(echo "$prec") <(echo "$temp") \
<(echo "$wind") <(echo "$win2") <(echo "$gust") | head -n$hours | \
column -s $'\t' -t

echo
echo $(grep -m2 -E 'Sunrise|Sunset' "$wfile" | sed1 | sed2) | column -s -t
read

# Timecheck has to be the last line no blanks.
# Timecheck 13

30 seconds of weather

#!/bin/bash

##      Yahoo weather forcast extraction

##      This program is free software; you can redistribute it and/or modify
##      it under the terms of the GNU General Public License as published by
##      the Free Software Foundation; either version 2 of the License, or
##      (at your option) any later version.
##
##      This program is distributed in the hope that it will be useful,
##      but WITHOUT ANY WARRANTY; without even the implied warranty of
##      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##      GNU General Public License for more details.
##
##      You should have received a copy of the GNU General Public License
##      along with this program; if not, write to the Free Software
##      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
##      MA 02110-1301, USA

##      Credit to Pawel "azhag" Sadkowski <azhag@fluxboxpl.org>
##      Pogodynka 0.4
##      http://pogodynka.fluxboxpl.org/
##      from whom most of this code is borrowed.

##      robz

# URL taken from browser address bar, change to suit your location.
SITE="http://weather.yahoo.com/england/cheshire/\
macclesfield-28094/;_ylt=AsQsIG9SbtnVsg.9RWa1feeLYDIB?unit=c"


# you might need to apt-get this
BROWSER=w3m

FILE=/tmp/yahooweather.tmp

$BROWSER -dump $SITE | \
    sed -re '/^(\s+)?$/d;s/^(\s+)(.*)/\2/g;s/ °C/°/g;s/°/°C/g;' |\
    grep -A19 'Current' > $FILE

xterm -geometry 40x15 -T \
    'WEATHER' -e "\
    echo '30 Seconds of weather......';\
    echo 'Forcast for `date +%A`';\
    echo $(sed -n '1p' $FILE | sed 's/Current c/C/g');\
    echo $(sed -n '2p' $FILE);\
    echo 'Temperature: '$(sed -n '19p' $FILE);\
    echo 'Feels Like: '$(sed -n '4p' $FILE);\
    echo 'Range: '$(sed -n '20p' $FILE);\
    echo 'Pressure: '$(sed -n '6p' $FILE | sed 's/,//g;s/\...//g');\
    echo 'Visability: '$(sed -n '10p' $FILE);\
    echo 'Wind Dir/Spd: '$(sed -n '14p' $FILE | sed 's/km\/h/kph/g');\
    echo 'Humidity: '$(sed -n '8p' $FILE);\
    echo 'Dewpoint: '$(sed -n '12p' $FILE);\
    echo 'Sunrises @ '$(sed -n '16p' $FILE | sed 's/ AM//g');\
    echo 'Sunsets @ '$(sed -ne '18p' $FILE | sed 's/ PM//g' |\
    awk -F ':' '{print $1+12":"$2}');\
    echo -n 'Is quite enough!......';\
    tput civis;\
    sleep 30"

rm $FILE