scripts available
Moderators: Developers, Moderators
scripts available
I've written some VBScripts to extract data from an XML file from a WeatherStation. Anybody interested ?
Yeah, I'm interested. (NM)
(NM)
Matt Sommer, CCNA
Saginaw Valley State University, IT Services
University Center, MI
Saginaw Valley State University, IT Services
University Center, MI
Re: Yeah, I'm interested. (NM)
here you go:mlsommer wrote:(NM)
'
'wx.vbs <param1> <param2>
'
' param1 = type of retreived value
' 1 = path style (/weather/wind/current/dirdeg)
' 2 = name style (ServerRoom)
' param2 = text to be searched for, case sensitive !
' in case of '1' :
' attn: only use one '/' at the beginning, second one will be added by this script.
' this is because scripting soes not like two '//' at the command line
' in case of '2' :
' attn: names seperated by spaced should use '_' --> 'Server Room' MUST be 'Server_Room'
' '_' will be replaced in the script by spaces again
' ..
'example:
' wx 1 /weather/wind/current/value
' wx 2 Antenne_Tower
'
'------------------------------------
On Error Resume Next
Dim oArgs, fso, oFile, MyFile, Answer, XMLValue
Dim nodeDesc, nodeTemp
Set oArgs = WScript.Arguments
If oArgs.Count <> 2 Then Wscript.Quit(0)
'
Const XmlFile = "./wx.xml"
Set fso = CreateObject ("Scripting.FileSystemObject")
If not (fso.FileExists(XmlFile)) Then
Answer = GetUrl("http://cust.93.182.adsl.cistron.nl:8880/XML")
Set MyFile = fso.CreateTextFile (XmlFile)
MyFile.Write Answer
MyFile.Close
set MyFile = Nothing
End If
Set oFile = fso.GetFile (XmlFile)
if (DateDiff("s",oFile.DateLastModified,Now)> 240)Then
Answer = GetUrl("http://cust.93.182.adsl.cistron.nl:8880/XML")
Set MyFile = fso.CreateTextFile (XmlFile)
MyFile.Write Answer
MyFile.Close
Set MyFile = Nothing
End If
Set fso = Nothing
Set oFile = Nothing
If oArgs(0) = 1 Then
XMLValue = ReadXML ("/" & oArgs(1))
Wscript.StdOut.Write XMLValue
ElseIf oArgs(0) = 2 Then
XMLValue = ReadXML2 (oArgs(1))
Wscript.StdOut.Write XMLValue
End If
wscript.quit(0)
'------------------------------------------------------------------
Function ReadXML (param)
Set objXMLDoc = CreateObject("Msxml2.DOMDocument.4.0")
objXMLDoc.async = False
objXMLDoc.load(XmlFile)
Set Node = objXMLDoc.documentElement.selectSingleNode(param)
ReadXml = Node.Text
Set objXMLDoc = Nothing
Set Node = Nothing
End Function
Function GetURL(url)
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "GET", url, False, "", ""
.Send
GetURL = .ResponseText
End With
Set Retrieval = Nothing
End Function
Function ReadXML2 (param)
Set objXMLDoc = CreateObject("Msxml2.DOMDocument.4.0")
objXMLDoc.async = False
objXMLDoc.load(XmlFile)
objXMLDoc.setProperty "SelectionLanguage", "XPath"
Set NodeDesc = objXMLDoc.selectNodes("//weather/temperatures/temperature/description")
'grep value
Set NodeTemp = objXMLDoc.selectNodes("//weather/temperatures/temperature/current/value")
For i = 0 to (nodeDesc.length - 1)
'MsgBox param & "-" & nodeDesc.item(i).text & "-" & nodeTemp.item(i).text
If UCase(nodeDesc.item(i).text) = UCase(Replace(param,"_"," ")) Then
ReadXML2 = nodeTemp.item(i).text
Exit For
Else
ReadXML2 = "0"
End If
Next
Set ObjXMLDoc = Nothing
Set NodeDesc = Nothing
Set NodeTemp = Nothing
End Function
Who is online
Users browsing this forum: No registered users and 3 guests