Weather.com XML parser (.vbs) Thread last updated on 2006-07-10 20:59:07

Posted by member 321598 on 2006-07-10 20:59:07

Just copy the following into a text file and rename it to WeatherXML.vbs and put it in your theme directory.

To use, you have to pass it the zipcode/country code (for those outside US)

something like:
$PathtoScript$WeatherXML.vbs "xxxxx"

where "xxxxx" is your zip/country code


'************************************************************************
'*---WeatherXML.vbs *
'*---By: Mao *
'*---This script accepts a zip code and writes a text file *
'*---of all the available weather data via the weather.com XML stream *
'*---SEE [CONFIGURATIONS] *
'************************************************************************

'---[initialization codes DO NOT EDIT]---
'Define Explicit variables
Option Explicit
'User configurable inputs
Dim lspath, file, par, key, units, url, successbang, failurebang
'Function to parse the XML stream
Sub WriteWeather(Node,TS)
If Node.hasChildNodes() Then
'Recursively call function for each child node
Dim childNode
For Each childNode in Node.childNodes
WriteWeather childNode, TS
Next
Else
'No more child nodes, print text
TS.Write Node.text & VbCrLf
End If
End Sub
'---[End Initialization code]---


'************************************************************************
'---[CONFIGURATIONS]---

'Output File name
file="Weather.txt"

'Your partner ID
par="1004449772"

'Your key
key="7cd95a46b1cf3b39"

'Define "s" for standard units, "m" for metric
units="s"

'Bang to be executed on success
successbang="!about"

'Bang to be executed on fail
failurebang="!alert 'Failed!'"

'************************************************************************


'---[DO NOT EDIT BEYOND THIS POINT]---
'Cat url
url="http://xoap.weather.com/weather/local/" & WScript.Arguments(0) & "?cc=*&dayf=3&par=" & par & "&key=" & key & "&unit=" & units

'Define vars
Dim objArgs, objShell, objXML, objFSO, objTS, objWMIService, objProcess
Dim Root, itemProcess

'Get process, shell, and XML objects
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set objProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'litestep.exe'")
Set objShell = CreateObject("WScript.Shell")
Set objXML = CreateObject("Microsoft.XMLDOM")

'Wait for XML to load
objXML.async = "false"

'Find path of LS
For Each itemProcess in objProcess
lspath="""" & itemProcess.ExecutablePath & """"
Next

'Check to see if XML was loaded
If objXML.load(url) Then
'Get elements and Output file objects
Set Root = objXML.documentElement
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTS = objFSO.CreateTextFile(file)

'Call write function
WriteWeather Root, objTS

'Sleep for 2 seconds
WScript.Sleep 2000

'Execute success bang
objShell.Run lspath & successbang
Else
'Execute failure bang
objShell.Run lspath & failurebang
End If