NOAA Weather Script

Posted on
Tue Feb 08, 2011 10:50 pm
jay (support) offline
Site Admin
User avatar
Posts: 18219
Joined: Mar 19, 2008
Location: Austin, Texas

Re: NOAA Weather Script

Here's the script I use. It's not pretty but it gets the job done. Basically, for each background script I want to monitor I check to see if there's an osascript process running that script. If there isn't then I log that the respective script isn't running, log the approximate time the script stopped, speak a message if configured to do so, and then execute an action group that starts the script back up. Most of that was my attempt at trying to debug why it was happening - unfortunately I could never figure it out. Nothing in the console around the time the scripts stopped. I was running it every minute while debugging but now I'm running it every 5 minutes. You should run it as an external script (not embedded) since there are no timeouts/trys, etc.

Code: Select all
set theScriptPath to "/Library/Application Support/Perceptive Automation/Indigo 5/Scripts/"
set scriptList to {itunes:false, noaa:false, pv:false, ical:false, airfoil:false}
tell application "System Events"
   set processIdList to unix id of every process whose name contains "osascript" or name contains "osasubr"
   repeat with procID in processIdList
      set thePSResult to (do shell script "ps -p " & procID)
      if thePSResult contains "iTunes sync.scpt" then
         set itunes of scriptList to true
      else if thePSResult contains "Weather NOAA sync.scpt" then
         set noaa of scriptList to true
      else if thePSResult contains "Phonevalet Background Script.scpt" then
         set pv of scriptList to true
      else if thePSResult contains "iCal Alarm Processor.scpt" then
         set ical of scriptList to true
      else if thePSResult contains "Airfoil Sync.scpt" then
         set airfoil of scriptList to true
      end if
   end repeat
end tell
set hour to (hours of (current date))
--set shouldSpeakMessage to ((hour > 7) and (hour < 23))
set shouldSpeakMessage to false
tell application "IndigoServer"
   if not (itunes of scriptList) then
      log "iTunes Sync Script not running" using type "Error"
      set value of variable "iTunesSync_end" to (current date) as string
      if shouldSpeakMessage then pauseiTunesAndSay("iTunes script restarted")
      execute group "Start iTunes Sync Script"
   end if
   if not (noaa of scriptList) then
      log "NOAA Script not running" using type "Error"
      set value of variable "NOAA_end" to (current date) as string
      if shouldSpeakMessage then pauseiTunesAndSay("Weather script restarted")
      execute group "Start NOAA Script"
   end if
   if not (pv of scriptList) then
      log "PhoneValet Background Script not running" using type "Error"
      if shouldSpeakMessage then pauseiTunesAndSay("Phone Valet script restarted")
      set value of variable "PV_end" to (current date) as string
      execute group "Start PhoneValet Script"
   end if
   if not (ical of scriptList) then
      log "iCal Alarm Processor Script not running" using type "Error"
      set value of variable "iCalAlarmProcessor_end" to (current date) as string
      if shouldSpeakMessage then pauseiTunesAndSay("iCal script restarted")
      execute group "Start iCal Alarm Script"
   end if
   if not (airfoil of scriptList) then
      log "Airfoil Sync Script not running" using type "Error"
      if shouldSpeakMessage then pauseiTunesAndSay("Airfoil script restarted")
      execute group "Start Airfoil Sync Script"
   end if
end tell

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Feb 17, 2011 3:37 pm
hammer32 offline
Posts: 66
Joined: May 13, 2006
Location: Copperas Cove, TX

Re: NOAA Weather Script

I've only been using the NOAA script for about two weeks. I'm not at home, so it took me a while to realize that the conditions were always the same. The variables show that it last got new data several days ago. I changed how I run the script from a startup script to a time/date action that runs every 10 minutes. The problem now is that it will get good data now, then ten minutes later (the next time it runs) it shows data from the first time I manually ran it. Ten minutes later good data, ten minutes following that it's back to the original data.

I don't know what's going on, but if it can't reach the NOAA servers, does it revert to data from the first time it ran?

Posted on
Thu Feb 17, 2011 3:45 pm
jay (support) offline
Site Admin
User avatar
Posts: 18219
Joined: Mar 19, 2008
Location: Austin, Texas

Re: NOAA Weather Script

The unmodified script won't update any data if it can't contact the NOAA servers. Not sure what your modified script does. Are you sure you don't have them both running (the unmodified stay-open script and the modified script run from the t/d action)?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Feb 17, 2011 6:07 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: NOAA Weather Script

hammer32 wrote:
?..I don't know what's going on, but if it can't reach the NOAA servers, does it revert to data from the first time it ran?

just a thought... Have you verified manually (via a browser) that the data actually updates more often than every twenty minutes. There is certainly some periodicity to the updates. If it is longer than 10 minutes, that might account for what you have observed.

If the data really is updating every 10 minutes, then I'd have to agree with Jay. Check to make sure the script is not running in the background.

Posted on
Mon Jun 06, 2011 2:34 pm
hammer32 offline
Posts: 66
Joined: May 13, 2006
Location: Copperas Cove, TX

Re: NOAA Weather Script

Hello,

I'm getting this error, I'm pretty sure it's from the NOAA Weather Script:

GetXMLfile:An error of type -10810 has occurred.(-10810)

Is anyone else getting it also?

Thanks!

Posted on
Fri Jun 17, 2011 2:46 am
HighwayStar offline
Posts: 82
Joined: Sep 07, 2005
Location: NY

Re: NOAA Weather Script

Yes it's the NOAA script. I'm getting the same error or it's timing out. Data hasn't updated since the 6th. Sometimes they're working on the servers but it's been over ten days...

Posted on
Fri Jun 17, 2011 7:27 am
jay (support) offline
Site Admin
User avatar
Posts: 18219
Joined: Mar 19, 2008
Location: Austin, Texas

Re: NOAA Weather Script

It also can be station dependent - I've not had any interruptions (last update about 20 minutes ago). Try a different station.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Jun 17, 2011 11:40 am
HighwayStar offline
Posts: 82
Joined: Sep 07, 2005
Location: NY

Re: NOAA Weather Script

I changed it from WNYC (Central Park NYC) to WJFK (JFK Airport NY) and am still getting the timeout error 1712. Last update was 8:51pm June 6th. Ran like a champ until then...

Posted on
Fri Jun 17, 2011 1:03 pm
jay (support) offline
Site Admin
User avatar
Posts: 18219
Joined: Mar 19, 2008
Location: Austin, Texas

Re: NOAA Weather Script

Just tried both of them from here and they worked fine. This indicates one of the following:

1) A network issue at your house is keeping you from reaching the NOAA site. To ensure that your Mac can get to the NOAA site open Safari on that Mac and try the URL directly that the script uses: http://www.nws.noaa.gov/data/current_obs/KNYC.xml (note that WNYC and WJFK seem to redirect to KNYC and KJFK respectively). You should get an XML page that renders in HTML (the XML file specifies an XSLT translation doc to convert it to HTML). But if you view source it should look like a normal XML file.
2) The URL Access Scripting application, which the script uses to download the XML file, is having an issue. Not sure what you can do about that - maybe reboot your Mac (although I'm pretty sure you've tried that). You can try running this in Script Editor and see if you get any better error messages:

Code: Select all
tell application "Finder"
   set myFile to ((path to temporary items) as string) & "noaa_sync_temp.xml"
end tell
tell application "URL Access Scripting"
   download "http://www.nws.noaa.gov/data/current_obs/KNYC.xml" to file myFile replacing yes
end tell


That's basically what the script is doing to get the XML data it uses.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Jun 17, 2011 1:36 pm
HighwayStar offline
Posts: 82
Joined: Sep 07, 2005
Location: NY

Re: NOAA Weather Script

Thanks Jay. The URL works fine and I honestly thought I had rebooted. I stopped & started the server many times but guess I never rebooted. The reboot cleared it. Working from both stations. I'll go stand in the corner now... :oops:

Posted on
Fri Jun 17, 2011 2:04 pm
jay (support) offline
Site Admin
User avatar
Posts: 18219
Joined: Mar 19, 2008
Location: Austin, Texas

Re: NOAA Weather Script

LOL - no problem. The URL Access Scripting and System Events applications are somewhat unreliable - not sure why exactly... ;)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Jul 09, 2011 8:50 am
gadgetfreak98 offline
Posts: 47
Joined: Jan 08, 2009

Re: NOAA Weather Script

I'm having an issue with getting the NOAA data to update without launching endless numbers of osascript processes. I have the NOAA script set up as a startup process. But how do I then have it auto-update? If I set up a schedule to execute the script ever 10 min (as I had tried), the osascript processes pile up, according to Activity Monitor.

I'm sure I'm missing something relatively obvious (perhaps within the script itself?), but I'm not in any way an Applescript expert, so I guess it's not so obvious to me! Could someone advise? Thanks!

Posted on
Sat Jul 09, 2011 9:28 am
jay (support) offline
Site Admin
User avatar
Posts: 18219
Joined: Mar 19, 2008
Location: Austin, Texas

Re: NOAA Weather Script

The NOAA script cycles forever once started, so you only need to start it up when the server starts up. By default it refreshes every 30 minutes. The usage instructions are at the top fo the script, but here they are:

Description:

Weather NOAA Script will poll the NOAA web site and retreive the latest
weather information for the specified station code whenever the script is run.
The weather information will be saved into Indigo Variables that you can use
as desired.

Usage Instructions:

1) Create a Trigger Action of Type "Indigo Server Startup" and select
an Action Type of "Execute AppleScript" that executes this script file. This
script file will then start as a separate process and run as long as the
IndigoServer is running. IndigoServer automatically terminates the script
when it shuts down.

2) Lookup your NOAA broadcast station code by going to:

http://www.nws.noaa.gov/data/current_obs/

And then inside Indigo use the Variable Window to set the value of the
variable _Weather_Fetch_Station to match your desired 4 letter station
code.

3) Wait up to 30 minutes for the next refresh, or stop and restart the
Indigo Server.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Jul 09, 2011 2:18 pm
gadgetfreak98 offline
Posts: 47
Joined: Jan 08, 2009

Re: NOAA Weather Script

Thanks Jay. And is there any way of specifying the refresh interval? Also, I thought this was how I was set up but I will start again. Has the script itself changed at all in the last year or year and a half? Maybe I have an old version? Or is the latest included in indigo v5?

Thanks!

Posted on
Sat Jul 09, 2011 3:18 pm
jay (support) offline
Site Admin
User avatar
Posts: 18219
Joined: Mar 19, 2008
Location: Austin, Texas

Re: NOAA Weather Script

Edit the script using the AppleScript Editor - change the value on this line:

Code: Select all
property variableRefreshRate : 30 * 60 -- refresh Indigo variables every 30 minutes


To whatever you want it to be. I think the last change to that script was with Indigo 4.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Who is online

Users browsing this forum: No registered users and 13 guests