Evolution of a script
-------------------------------------------------------------------------------------------------------------
Notice: Comments are correct the scripts need to be updated.
-------------------------------------------------------------------------------------------------------------
Do not have time to do it now , but it isin the queue......
Someone had written a script to grab the weather from the web. A script is like a todo list for the computer. Even if you are not a programmer, you will see the added lines give the script more potential or power. Everything becomes less and less cryptic to use. How you interact with it is sometimes considered what is called the user interface.
That yielded:
That is great if you live in Woonsocket, RI. What if you live somewhere else. I had no idea What a warning zone was... Had to check it out. Found where I could get the zones in county form but not city form. But that meant a lot of lookups and manual work.
There had to be a better way. After a lot of research, trial, and error I came up with this script. Stripped out the remarks for sake of space.
$ ./gwp7.sh Polk FL
National Weather Service
__________________________________________________ ________________
Polk , FL
Current Local Conditions at:
Gilbert Field
Lat: 28.05 N Lon: 81.75 W Elev: 144 ft
Last Update: 11/01/11, 08:53 AM EDT
Weather: Fair
Temperature: 63°F (17°C)
Humidity: 87 %
Wind Speed: N 9 MPH
Barometer: 30.14 in. (1020.5 mb)
Dewpoint: 59°F (15°C)
Visibility: 10.00 mi.
__________________________________________________ ________________
Code:
Now you could at least type in the county and state to get the weather without looking it up. But what about a new user? They may not be familiar with that trick. So I did a minimal amount of window dressing to make it just a bit easier.
Weather printout
Enter the State: LA
County: Cameron
-------------------------------------------------
National Weather Service
__________________________________________________________________
Cameron , LA
Current Local Conditions at:
Lake Charles Regional Airport
Lat: 30.12 N Lon: 93.22 W Elev: 15 ft
Last Update: 11/01/11, 09:53 AM CDT
Weather: Fair
Temperature: 62°F (17°C)
Humidity: 58 %
Wind Speed: E 5 MPH
Barometer: 30.22 in. (1024.1 mb)
Dewpoint: 47°F (8°C)
Visibility: 10.00 mi.
__________________________________________________________________
Code
So now what started as a one line program that was hard to deal with has become almost usable.. We could use zenity to make some fancy gui interface, but I think you get the idea.
Note: Yes, I know I left out the shell type, but that changes with the turn anyway. Also these scripts may not work for California and other places where they do not use counties as the basis for reports.
Lastly, http://mobile.weather.gov is a great source for looking to find web pages to get weather data from. You can even get weather (radar) pictures to and add them to your script. That will make things even more user friendly. For Tallahasse, Florida.
$ wget http://radar.weather.gov/ridge/Thumbs/TLH.png --2011-11-02 03:22:12-- http://radar.weather.gov/ridge/Thumbs/TLH.png Resolving radar.weather.gov... 209.234.250.138, 209.234.250.202 Connecting to radar.weather.gov|209.234.250.138|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 29455 (29K) [image/png] Saving to: `TLH.png' 100%[======================================>] 29,455 --.-K/s in 0.05s 2011-11-02 03:22:12 (561 KB/s) - `TLH.png' saved [29455/29455]
$ convert TLH.png TLH.jpg
Convert to ascii
$ jp2a -i TLH.jpg > tlh.txt
$ cat tlh.txt
Add cat tlh.txt to your script to get the radar picture.
Update: Found an image converter I like better.
$ sudo apt-get install caca-utils
Get the pic
getpic:
[code]
DAY=$(date +"%m%d%y%H%M%S")
picfn="pic$DAY.png"
# echo $picfn wget http://radar.weather.gov/ridge/Thumbs/HGX.png -O hgx$DAY.png
[/code]
Convert
$ img2txt -W 80 -f utf8 img2txt -W 80 -H 25 -f utf8 hgx110711051503.png > hgx110711051503.txt
Display
$ cat hgx110711051503.txt
From:
To:
Notice: Comments are correct the scripts need to be updated.
-------------------------------------------------------------------------------------------------------------
Do not have time to do it now , but it isin the queue......
Someone had written a script to grab the weather from the web. A script is like a todo list for the computer. Even if you are not a programmer, you will see the added lines give the script more potential or power. Everything becomes less and less cryptic to use. How you interact with it is sometimes considered what is called the user interface.
lynx -dump "http://mobile.weather.gov/port_mp_ns.php?select=3&CityName=Woonsocwa
That yielded:
National Weather Service __________________________________________________________________ Woonsocket, RI Current Local Conditions at: Smithfield Lat: 41.91 N Lon: 71.4 W Elev: 440 ft Last Update: 10/31/11, 11:35 PM EDT Weather: Fair Temperature: 36°F (2°C) Humidity: 93 % Wind Speed: E 5 MPH Barometer: 30.36 in Dewpoint: 34°F (1°C) Wind Chill: 32°F (0°C) Visibility: 10.00 mi. __________________________________________________________________ [BUTTON Input] (not implemented)_____________________
That is great if you live in Woonsocket, RI. What if you live somewhere else. I had no idea What a warning zone was... Had to check it out. Found where I could get the zones in county form but not city form. But that meant a lot of lookups and manual work.
There had to be a better way. After a lot of research, trial, and error I came up with this script. Stripped out the remarks for sake of space.
$ ./gwp7.sh Polk FL
National Weather Service
__________________________________________________ ________________
Polk , FL
Current Local Conditions at:
Gilbert Field
Lat: 28.05 N Lon: 81.75 W Elev: 144 ft
Last Update: 11/01/11, 08:53 AM EDT
Weather: Fair
Temperature: 63°F (17°C)
Humidity: 87 %
Wind Speed: N 9 MPH
Barometer: 30.14 in. (1020.5 mb)
Dewpoint: 59°F (15°C)
Visibility: 10.00 mi.
__________________________________________________ ________________
Code:
if [ $# -lt 2 ] ; then echo "You wrote: $0 $*" echo "Please use the format: $0 County ST" exit fi state=$2 county=$1 county="$county " statecode="$stateZ" echo lynx -dump http://alerts.weather.gov/cap/$state.php?x=2 | grep "$county" > x grep -e "$statecode" x > y grep -e $county y > z thecode=$(tail -1 z | sed 's/^.*\(......\)$/\1/') lynx -dump "http://mobile.weather.gov/port_mp_ns.php?select=3&CityName=$county&site=BOX&State=$state&warnzone=$thecode" # # Voice playback # lynx -dump "http://mobile.weather.gov/port_mp_ns.php?select=3&CityName=$county&site=BOX&State=$state&warnzone=$thecode" | festival --tts
Now you could at least type in the county and state to get the weather without looking it up. But what about a new user? They may not be familiar with that trick. So I did a minimal amount of window dressing to make it just a bit easier.
Weather printout
Enter the State: LA
County: Cameron
-------------------------------------------------
National Weather Service
__________________________________________________________________
Cameron , LA
Current Local Conditions at:
Lake Charles Regional Airport
Lat: 30.12 N Lon: 93.22 W Elev: 15 ft
Last Update: 11/01/11, 09:53 AM CDT
Weather: Fair
Temperature: 62°F (17°C)
Humidity: 58 %
Wind Speed: E 5 MPH
Barometer: 30.22 in. (1024.1 mb)
Dewpoint: 47°F (8°C)
Visibility: 10.00 mi.
__________________________________________________________________
Code
clear echo echo " Weather printout" echo read -p "Enter the State: " state read -p " County: " county echo "-------------------------------------------------" echo # state=TX # county=Galveston county="$county " statecode="$stateZ" lynx -dump http://alerts.weather.gov/cap/$state.php?x=2 | grep "$county" > x grep -e "$statecode" x > y grep -e $county y > z thecode=$(tail -1 z | sed 's/^.*\(......\)$/\1/') lynx -dump "http://mobile.weather.gov/port_mp_ns.php?select=3&CityName=$county&site=BOX&State=$state&warnzone=$thecode" # lynx -dump "http://mobile.weather.gov/port_mp_ns.php?select=3&CityName=$county&site=BOX&State=$state&warnzone=$thecode" | festival --tts
So now what started as a one line program that was hard to deal with has become almost usable.. We could use zenity to make some fancy gui interface, but I think you get the idea.
Note: Yes, I know I left out the shell type, but that changes with the turn anyway. Also these scripts may not work for California and other places where they do not use counties as the basis for reports.
Lastly, http://mobile.weather.gov is a great source for looking to find web pages to get weather data from. You can even get weather (radar) pictures to and add them to your script. That will make things even more user friendly. For Tallahasse, Florida.
$ wget http://radar.weather.gov/ridge/Thumbs/TLH.png --2011-11-02 03:22:12-- http://radar.weather.gov/ridge/Thumbs/TLH.png Resolving radar.weather.gov... 209.234.250.138, 209.234.250.202 Connecting to radar.weather.gov|209.234.250.138|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 29455 (29K) [image/png] Saving to: `TLH.png' 100%[======================================>] 29,455 --.-K/s in 0.05s 2011-11-02 03:22:12 (561 KB/s) - `TLH.png' saved [29455/29455]
$ convert TLH.png TLH.jpg
Convert to ascii
$ jp2a -i TLH.jpg > tlh.txt
$ cat tlh.txt
Add cat tlh.txt to your script to get the radar picture.
Update: Found an image converter I like better.
$ sudo apt-get install caca-utils
Get the pic
getpic:
[code]
DAY=$(date +"%m%d%y%H%M%S")
picfn="pic$DAY.png"
# echo $picfn wget http://radar.weather.gov/ridge/Thumbs/HGX.png -O hgx$DAY.png
[/code]
Convert
$ img2txt -W 80 -f utf8 img2txt -W 80 -H 25 -f utf8 hgx110711051503.png > hgx110711051503.txt
Display
$ cat hgx110711051503.txt
From:
To:
Apparently they changed the API between client server in the last 2 months (pre mid-july 2012), I used this stuff extensively on my phone web-browser because the reports were very quick to load (great when traveling in country with spotty cell phone data support) & simple (easy to read without pressing extra buttons or messing with phone window scrolling - safer for those foolish enough to drive while trying to read phone).... the new interface is much "prettier" & has some new .experimental content (hour by hour forecasts), but seems to have totally lost the fact that the site is for mobile devices and KISS (Keep it Simple Silly). Plus with the old API the site was quite usable on event the smallest & cheapest devices, a good design intro to what the government should support as least common denominator an be found in the scoping statement of this old proposed standard: http://www.w3.org/TR/1998/NOTE-compactHTML-19980209/
ReplyDeleteUpdate, I'm soooo happy !!!, they (NOAA) did the great thing & moved the old API. I just missed it!! To keep your stuff working you'll need to use cell.weather.gov instead of mobile.weather.gov. Thank you NOAA for saving the old while exploring the new!!
ReplyDelete