Announcement

Collapse
No announcement yet.

Weather Warnings Script Update

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Weather Warnings Script Update

    Weather Warnings is the only script I have that isn't .NET and while I'd prefer to not be running anything VB6, I'm kind of a "If it ain't broke, don't fix it!" kind of guy. Well Weather Warnings is now broke...sort of.

    So obviously if you are using this as well you see that they are going to change the URL and provide a much nicer XML interface. Since the link is changing, the URL in the script will need to change. However, the way the script parses the XML will need to change as well.

    This is my test modification so I offer it up with no warranties or guarantees so use at your own risk. I'm just looking for someone else to help work the bugs out.

    Chances are it will have to change again anyway since the new URL contains "-beta" so I'm assuming they will change that at some point, but it's trivial as long as they don't mess with the XML format too much.

    I tried to keep the changes close to the style of how the original was coded. I've modified the original so much that I can't provide a straight up replacement of the entire file. So I provide modifications in two parts below.

    First, add these declarations at the end of his declaration block and right before the line:
    RepeatWarnings = hs.GetINISetting("Settings", "RepeatWarnings", "", "weatherwarnings.ini")
    PHP Code:
    Dim ChildNode
    Dim EventNode
    Dim IdNode
    Dim warningDoc
    Dim warningURL
    Dim FoundWarning 
    Then look for this code block which you will replace:
    PHP Code:
            Page "http://www.weather.gov/alerts/wwarssget.php?zone=" zone ""

            
    Set myDoc CreateObject("Microsoft.XMLDOM")
            
    myDoc.async=false
            myDoc
    .Load(Page)
            
    Set myList myDoc.getElementsByTagName("item")
            For 
    Each Node In myList
                 
    'add by Jay Fro 10/22/05 to ignore alert types set by user in the .ini file
                 DontProcess = hs.GetINISetting("Settings", "DontProcess", "", "weatherwarnings.ini")
                 Set objRegExp = New RegExp
                 strSearch = Node.ChildNodes(0).Text
                 objRegExp.Pattern = DontProcess
                 objRegExp.Global= True
                 objRegExp.IgnoreCase = True
                 blnFind = objRegExp.Test(strSearch)

                 title = Node.ChildNodes(0).Text
                 description = Node.ChildNodes(2).Text

                If blnFind Then 
    Replace that code block with:

    PHP Code:
        ' BEGIN REPLACE CODE BLOCK
        ' 
    At some point this URL will change againprobably removing -beta        
        Page 
    "http://www.weather.gov/alerts-beta/wwaatmget.php?x=" zone ""

        
    Set myDoc CreateObject("Microsoft.XMLDOM")
        
    myDoc.async False
        myDoc
    .Load (Page)
        
        
    'Get all of the entries (the various warnings)
        Set myList = myDoc.getElementsByTagName("entry")
        
        Set warningDoc = CreateObject("Microsoft.XMLDOM")
        warningDoc.async = False
        
        '
    This will handle multiple warnings on the page
        
    For Each Node In myList

            FoundWarning 
    False
            warningURL 
    ""
            
    warningtype ""
            
    warning ""
            
    Title ""
            
    Description ""
            
            'Get the id which is the URL to the actual warning page
            For i = 0 To Node.childNodes.length - 1
                If Node.childNodes(i).nodeName = "id" Then
                    warningURL = Node.childNodes(i).nodeTypedValue
                    Exit For
                End If
            Next

            If warningURL <> "" Then    
            
                '
    Load the actual warning URL
                warningDoc
    .Load (warningURL)

                
    'Get the actual alert
                Set EventNode = warningDoc.getElementsByTagName("alert")
            
                '
    Get the information node of the alert which has the alert detailsThere should be only one event (alertnode per page.
                For 
    Each ChildNode In EventNode
                    
    For 0 To ChildNode.childNodes.length 1
                        
    If ChildNode.childNodes(i).nodeName "info" Then
                            Set IdNode 
    ChildNode.childNodes(i)
                            
    FoundWarning True
                            
    Exit For
                        
    End If
                    
    Next
                Next

                
    If (FoundWarningThen
                    
    'Get the event (warning type) and the description
                    For i = 0 To IdNode.childNodes.length - 1
                        If IdNode.childNodes(i).nodeName = "event" Then
                            Title = IdNode.childNodes(i).nodeTypedValue
                        End If
                        If IdNode.childNodes(i).nodeName = "description" Then
                            Description = IdNode.childNodes(i).nodeTypedValue
                        End If
                    Next
                End If
            End If
            
            If Title="" And Description="" Then
                '
    There are no warnings so force this flag to be set so nothing is processed
                blnFind 
    True
            
    Else
            
                
    'add by Jay Fro 10/22/05 to ignore alert types set by user in the .ini file
                DontProcess = hs.GetINISetting("Settings", "DontProcess", "", "weatherwarnings.ini")
                Set objRegExp = New RegExp
                strSearch = Title
                objRegExp.Pattern = DontProcess
                objRegExp.Global = True
                objRegExp.IgnoreCase = True
                blnFind = objRegExp.Test(strSearch)
            End If

            If blnFind Then

            ' 
    END REPLACE CODE BLOCK 
    Again my code is slightly different, but I think this should work. I'd just like someone else to help clean it up. While I'd really prefer a nice .NET script that does the same, I'm sure some people would prefer to just keep using this so hopefully we can get it working.

  • #2
    Thanks for the update!

    I've implemented the changes, now just have to wait for a warning to occur!

    Comment


    • #3
      I have it running

      GatorEye,

      I have it running. I will keep an eye on it.

      Comment


      • #4
        Just had a "Special Weather Advisory" alert spoken to me!

        Looks like it's doing something worthwhile!

        Thanks!

        Comment


        • #5
          Looks better than mine!

          I've been working on this for several days but took a different approach from GatorEye. I ended up putting the warnings and summaries into arrays so I could parse them easier since I use both HS and MainLobby. I used taglines of "title" and "summary" to get the warning titles and descriptions. It works but his version looks more elegant than mine! I'll have to give his approach a try also.

          Since we haven't had any warnings here in West Texas for a while I found that I could look at the NWS site and find where there were warnings issued. I then used that county code in the script instead of my "zone".

          For example, right now (1404 CST 21 Jan) there are three warnings out for Missoula Montana - http://www.weather.gov/alerts-beta/w...t.php?x=MTC063

          You can log onto this url and then find current warnings for anywhere in the country.

          I just need to remember to change my zone back to here! :-)

          Tony

          Comment


          • #6
            Whoops!

            I had redone my script to use the NWS county codes (ie TXC###) instead of the zone code (ie TXZ###). Don't try using the county code in the new script as it won't parse correctly and it will just drone on and on.

            Since I have been setting off alarms and speech over the last several days during testing, this really decreased the WAF!

            Comment


            • #7
              Originally posted by indiggio View Post
              Just had a "Special Weather Advisory" alert spoken to me!

              Looks like it's doing something worthwhile!

              Thanks!
              I'm glad it appears to be working!

              Comment


              • #8
                Originally posted by atalbert View Post
                I've been working on this for several days but took a different approach from GatorEye. I ended up putting the warnings and summaries into arrays so I could parse them easier since I use both HS and MainLobby. I used taglines of "title" and "summary" to get the warning titles and descriptions. It works but his version looks more elegant than min
                I had to laugh when you said mine looks elegant because I sure didn't feel that way (I didn't even want to post it). And if yours works, it's just as "elegant" as mine no matter what the code looks like.

                Actually if you have a better or different way to do it - go ahead and post it since maybe your way is better. Again, I didn't really want to rewrite the entire thing, I just tried to shoehorn in some code that was something like the old code, but that would work.

                Since their URL's still say "beta" I'm not sure how the thing with the codes are going to work...will the old ones still work or only the new ones? I'm using the old zone codes not the county ones.

                The new format is much nicer - I like how they've broken out the data so we can speak the warning without the need to parse all the extra garbage out of it.

                Comment


                • #9
                  Glad to have given you a laugh!

                  Originally posted by GatorEye View Post
                  I had to laugh when you said mine looks elegant because I sure didn't feel that way.
                  Ah, too modest! My script is so heavily modified and "patched up" that I would hesitate to let anyone see it :-)

                  For anyone who has not modified things as much as I have, I would recommend using your modification to Tom Caldwell's script. It appears to work well and maintains the basic structure that he set out. It's quite quick to "change over" from the old script. For what it's worth I consider it a nice piece of work.

                  Cheers.

                  Tony

                  Comment


                  • #10
                    I just got an alert this morning that contained only the following "This alert has expired". I don't know if the new weather feed is sending out more details than this (and the script modifications are not picking it up) or if there is not other information? This warning also triggered the weather alert beep but then nothing was spoken. I haven't dug into the script as I know that some here are more familiar with it. Thanks.

                    Comment


                    • #11
                      Has something changed?

                      Gator,

                      Has something changed in the NWS formatting of the warning? Your revised script is now giving me a long string instead of the warning type.

                      For example, testing right now with TNZ018 (Tennesee - which has winter storm warning) the script reports "http://www.weather.gov/alerts-beta/wwacapget.php?x=TN20110125154500WinterStormWatch201101270600 00TN.MRXWSWMRX.c7b55b44b125f27bfb4e4c35e981aa7b2011-01-25T10:45:00-05:00" rather than the expected "Winter Storm Watch".

                      Perhaps I somehow inserted a "typo". If no one else sees this sort of thing I"ll go back and review the entire script.

                      Tony

                      Comment


                      • #12
                        Originally posted by simonmason View Post
                        I just got an alert this morning that contained only the following "This alert has expired". I don't know if the new weather feed is sending out more details than this (and the script modifications are not picking it up) or if there is not other information? This warning also triggered the weather alert beep but then nothing was spoken. I haven't dug into the script as I know that some here are more familiar with it. Thanks.
                        I saw this today during testing. I think what causes this is the fact that the list of warnings is on one page and the warning itself is on another. When I was testing right at the bottom of the hour, the page listed two warnings, then when I went to the detail, one said it had expired.

                        So from that my guess is that it's possible that the script could run and get a list of the warnings and in the time it goes to get the details, it is "expired". On the detail page it would be nice if there was an XML node that was actually populated, but from what I saw in the source, it looks like the best fix (kludge) is parsing the description for "expired".

                        Thus my guess is that if you make this change:

                        Before:
                        PHP Code:
                        If Title="" And Description="" Then 
                        After:

                        PHP Code:
                        If (Title="" And Description="") Or InStr(1,Description"expired"vbTextCompare) > 0 Then 
                        that should prevent the expired warning from being processed so you shouldn't hear the tone or have that warning assigned to a device. I didn't test it, but it should work.

                        I'm hoping when Steve finishes up his .NET version, people would replace the old one with his. He's doing a great job with it.

                        Hope this helps.

                        Comment


                        • #13
                          Originally posted by atalbert View Post
                          Gator,

                          Has something changed in the NWS formatting of the warning? Your revised script is now giving me a long string instead of the warning type.

                          For example, testing right now with TNZ018 (Tennesee - which has winter storm warning) the script reports "http://www.weather.gov/alerts-beta/wwacapget.php?x=TN20110125154500WinterStormWatch201101270600 00TN.MRXWSWMRX.c7b55b44b125f27bfb4e4c35e981aa7b2011-01-25T10:45:00-05:00" rather than the expected "Winter Storm Watch".

                          Perhaps I somehow inserted a "typo". If no one else sees this sort of thing I"ll go back and review the entire script.

                          Tony
                          Let me know if you found anything because I tested the script with your zone and it worked ok for me when I debugged it. Actually it caused some excitement in the house when the announcement came regarding the potential for snow.

                          I looked at the page source and it didn't look like anything changed with their format, but the link is beta so I guess they could still be changing anything at this point.

                          As I mentioned, Steve's script will be much better dealing with the feed the proper way.

                          I'll see if there is anything I can change if it still doesn't work.

                          Comment


                          • #14
                            Originally posted by atalbert View Post
                            Gator,

                            Has something changed in the NWS formatting of the warning? Your revised script is now giving me a long string instead of the warning type.

                            For example, testing right now with TNZ018 (Tennesee - which has winter storm warning) the script reports "http://www.weather.gov/alerts-beta/wwacapget.php?x=TN20110125154500WinterStormWatch201101270600 00TN.MRXWSWMRX.c7b55b44b125f27bfb4e4c35e981aa7b2011-01-25T10:45:00-05:00" rather than the expected "Winter Storm Watch".

                            Perhaps I somehow inserted a "typo". If no one else sees this sort of thing I"ll go back and review the entire script.

                            Tony
                            Tony,

                            Not knowing exactly how the old pages worked, that link that was reported (the wwacapget.php CGI) is looks very familiar.

                            The idea of the new pages (as they've documented) is that instead of applications reading all of the alerts, they can first look at what amounts to an "index" at the state level. From there, they will summary info on what alerts are active, when they go into effect, when they expire, and what counties are affected (by FIPS6-4 codes). It also provides a web URL (just like what you reported here) to each XML file for each individual alert, which has more details.

                            The funny thing is that their beta alerts page still provides a list of the old county designators and the old area designators, even though none of are used any more (like your TNZ018).

                            Steve

                            Comment


                            • #15
                              Thanks for the Expired warning code. I made this change and will watch to see if I get anything.

                              Another question. I have a universal event running in the house between 11 and 7am that turns off text to speech. It sets hs.MuteSpeech to TRUE or FALSE. I noticed this morning that before 7am I got the beep from the weather script and no speech so I decided to dig in and turn the beep off during these times.

                              If I am reading the section below correctly. The first half plays the warning even if I have speech off or any other restrictions - these are warnings that are called out in the ini file as override.

                              So I should put the test of hs.speech in the second half - where I have indicated with ** to stop it playing the wave file when hs.speech is false? Thanks for the help.



                              PHP Code:
                                      if hs.IsOn(HouseCode DeviceNum) and warning <> "None" then
                                          
                              'checks to see if it should override speech. kind of warning
                                          if Ucase(UseSpeech) = Ucase("FALSE") then
                                             count = 0
                                             Do
                                                count = count + 1
                                                warntyp = trim(hs.stringItem(OverRideSpeech, count, ","))
                                               if warningtype = warntyp then
                                                    if Ucase(SpeakWholeWarn) = Ucase("True") then
                                                        if wavepath <> "" then
                                                            hs.PlayWavFile wavepath
                                                        end if
                                                        hs.Speak warning,True
                                                    else
                                                        if wavepath <> "" then
                                                             hs.PlayWavFile wavepath
                                                        end if
                                                        hs.Speak warningtype,True
                                                    end if
                                                end if
                                                hs.waitevents
                                             Loop Until warntyp = ""
                              **          else
                                               if Ucase(SpeakWholeWarn) = Ucase("True") then
                                                   if wavepath <> "" then
                                                        hs.PlayWavFile wavepath
                                                   end if
                                                   hs.Speak warning,True
                                               else
                                                   if wavepath <> "" then
                                                        hs.PlayWavFile wavepath
                                                   end if
                                                   hs.Speak warningtype,True
                                               end if
                                          end if
                                      end if 

                              Comment

                              Working...
                              X