Announcement

Collapse
No announcement yet.

Extracting string from RSS

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

    Extracting string from RSS

    Hi All,

    Hoping someone can help, i can feed the following link into a RSS in hstouch, but i want to extract a certian part and put it into a device (say for example T5 & T6

    The link is: http://www.cfa.vic.gov.au/restrictio...strict_rss.xml

    And from this link I am looking at extracting Central: LOW-MODERATE and pulling out the LOW-MODERATE and putting it in device T5 for today, and T6 for tomorrow's entry.

    Can anyone provide a sample i can play with to better understand.

    Thanks
    HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

    Facebook | Twitter | Flickr | Google+ | Website | YouTube

    #2
    Code:
    Imports System.XML
    
    Sub Main(ByVal Parms As Object)
    
    Dim XMLFire As New XmlDocument
    Dim XMLFireNodeList As XmlNodeList
    Dim XMLFireNode As XmlNode
    
    Dim MessageStr As String = ""
    Dim NextInstr As Integer = 0
    
    Dim After As Integer = 0
    Dim Before As Integer = 0
    Dim i As Integer = 0
    
    XMLFire.Load("http://www.cfa.vic.gov.au/restrictions/central-firedistrict_rss.xml")
    
    XMLFireNodeList = XMLFire.SelectNodes("//item")
    
    For Each XMLFireNode In XMLFireNodeList
    
    Before = Instr(XMLFireNode.Item("description").InnerText, "Central: ")
    
    If Before > 0 Then
    
    After = Instr(Before, XMLFireNode.Item("description").InnerText, "</p>")
    
    MessageStr = XMLFireNode.Item("description").InnerText.SubString(Before + 8, (After - Before - 9))
    
    If i = 0 then
    
    'this is for today
    hs.writelog("Date", XMLFireNode.Item("title").InnerText)
    hs.writelog("Message", MessageStr)
    
    hs.setdevicestring("T5", XMLFireNode.Item("title").InnerText & " - " & MessageStr, True)
    
    ElseIf i = 1
    
    'this is for tommorow
    
    hs.writelog("Date", XMLFireNode.Item("title").InnerText)
    hs.writelog("Message", MessageStr)
    
    hs.setdevicestring("T6", XMLFireNode.Item("title").InnerText & " - " & MessageStr, True)
    
    End If
    
    End If
    
    i = i + 1
    
    Next
    
    End Sub
    Is somewhere to start at least, you will need to make sure that you have the System.XML namespace reference in your ScriptingReferences entry in the HS config file first for the script to run. I think quite a few scripts use it now so you will probably have it already.

    As usual there are probably a few ways of doing this, but that to me seems to work.

    Just have to keep an eye on the feed as the slightest amendment may throw this script out.
    Last edited by mrhappy; August 17, 2012, 10:00 AM.

    Comment


      #3
      Thanks for your help, it works perfectly. Not sure if there is a more elegant way to do it, but i added a select case in there as well to set a device value. That way depending on the device value, the house can do different things. For example a device value of 6 means that if there was a fire, the potential for damage and danger would be much greater, so the house tries harder to contact me if i get a call, and i could even set it so that if there is a bushfire in my area, it calls my parents to warn them etc.

      Thanks for the help!

      Code:
      Select Case MessageStr
      
      Case "LOW-MODERATE"
      hs.SetDeviceValue("T5",1)
      Case "HIGH"
      hs.SetDeviceValue("T5",2)
      Case "VERY HIGH"
      hs.SetDeviceValue("T5",3)
      Case "SEVERE"
      hs.SetDeviceValue("T5",4)
      Case "EXTREME"
      hs.SetDeviceValue("T5",5)
      Case "CODE RED"
      hs.SetDeviceValue("T5",6)
      End Select
      HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

      Facebook | Twitter | Flickr | Google+ | Website | YouTube

      Comment

      Working...
      X