PDA

View Full Version : [Geektool] Updated Hazardous Weather Warning Script


WeatherWarning
Jan 11, 2013, 11:28 PM
I wanted to post updated code for the hazardous weather warning script. The original script (http://forums.macrumors.com/showthread.php?t=628023&page=84) broke after NOAA redesigned their site.

The updated AppleScript is as follows:
tell application "Finder"
set AppleScript's text item delimiters to ""
set warn to do shell script "curl \"http://forecast.weather.gov/MapClick.php?lat=[YOUR LAT HERE]&lon=[YOUR LONG HERE]&unit=0&lg=english&FcstType=dwml\""

-- count every warning!!
set AppleScript's text item delimiters to "<hazard"
set warn_string to every text item of (warn as string)

set amo_warn to 1
repeat with i in items of warn_string
if (i as string) contains "headline=\"" then
set amo_warn to amo_warn + 1
end if
end repeat

-- getting the warnings
set warnings to ""
set warn_number to 1

repeat until warn_number = (amo_warn)
set warn_number to warn_number + 1
try
set AppleScript's text item delimiters to "<hazard headline=\""
set temp_warnings to text item warn_number of (warn as string)
set AppleScript's text item delimiters to "\">"
set temp_warnings to text item 1 of temp_warnings
set AppleScript's text item delimiters to ""
set warnings to warnings & temp_warnings & return
end try
end repeat

if warnings = "" then
set warnings to " "
end if

return warnings

end tell
The script requires subscribing to the the XML from NOAA's forecast page for your area. On a typical forecast page (http://forecast.weather.gov/MapClick.php?lat=63.6941667&lon=-170.4788888&site=all&smap=1&searchresult=Savoonga%2C%20AK%2C%20USA), there should be a big orange XML button linking to the appropriate page.
http://i.imgur.com/uNsNF.jpg
The final product should look like this (with the Coastal Flood Statement being the hazardous condition):
http://i.imgur.com/LL0zu.png

Enjoy!