#!/bin/bash # Report NWS (USA) Conditions at KPTD and figlet them! # It runs as a cron job every 10 minutes. # Written by Tim on gopher://tildecow.com # See my about.txt and drop me a line to say "Hi"! # Grab the site we get data from as a string a=$(lynx -dump https://tgftp.nws.noaa.gov/weather/current/KPTD.html) # TIME time=$(date +"%I:%M %p") # CONDITIONS con=${a##*Sky conditions } # Remove the left part. con=${con%%\ Temperature*} # Remove the right part. con=$(echo "$con" | tr -s " ") # This var has weird extra whitespace # WIND wind=${a##*degrees) at } # Remove the left part. wind=${wind%%\ MPH*} # Remove the right part. # DIRECTION from=${a##*Wind from the } # Remove the left part. from=${from%%\ (*} # Remove the right part. from=$(echo "$from" | tr -s " ") # TEMPERATURE temp=${a##*Temperature } # Remove the left part. temp=${temp%%\ F (*} # Remove the right part. # HUMIDITY hum=${a##*Humidity } # Remove the left part. hum=${hum%%\%*} # Remove the right part. # PRESSURE pres=${a##*(altimeter) } # Remove the left part. pres=${pres%%\ in. Hg*} # Remove the right part. # Need pressure units presunits='"' # I discovered (when the temp went below zero) that I # had to send all the output to a file frst or else # figlet took the minus temperature as a command option # and crashed! echo -n " $time and ${con^}" > .temp.wx | tr '\n' ' ' # Originally I just displayed the second line including $wind # speed. Then one day the original file said "Wind Calm" # and bolluxed up everything. Hence this 'patch' if echo "$a" | grep -q "Wind Calm"; then echo "It's $temp F with calm winds" >> .temp.wx else echo "It's $temp F with $wind MPH winds" >> .temp.wx fi echo " Humidity is $hum % with the" >> .temp.wx echo " barometer reading $pres $presunits" >> .temp.wx figlet -w 120 -f small < .temp.wx > /var/gopher/weather # For reference, here is what the data I pull looks like in the raw... # [7]NWS Point Forecast for KPTD ( # _______________________________________________________________________ # # Conditions at [Dec 19, 2019 - 06:55 PM EST] # 2019.12.19 2355 UTC # Wind from the SSW (200 degrees) at 7 MPH (6 KT) #****NOTE**** THOUGH SOMETIMES THE PREVIOUS LINE JUST SAYS "Wind Calm" -Tim # Visibility 10 mile(s) # Sky conditions mostly cloudy # Temperature 0 F (-18 C) # Windchill -13 F (-25 C) # Dew Point -7 F (-22 C) # Relative Humidity 70% # Pressure (altimeter) 30.41 in. Hg (1029 hPa) # ob KPTD 192355Z AUTO 20006KT 10SM FEW028 SCT034 BKN040 M18/M22 A3041 # RMK AO2 # _______________________________________________________________________ #24 Hour Summary