RogerRuntings
MIS
I am trying to setup an automated weather update to show on some plasma screens.
I am able to use vbscript to query the yahoo weather service; my only problem is how to parse the XML that is downloaded. I need to get some text strings out of the XML in a certain format so that the application will know how to update based on each line of the text file,ie,:
Line1 (Place the weather is for)
Line2 (Weather condition ie, "Cloudy")
Line3 (Current Temp)
Line4 (High Temp)
Line5 (Low Temp)
etc
This is my code (which queries the XML and gets one big file):
' Retrieve the information over the web, using the WinHttp object
Dim WinHttpReq
Set WinHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")
Dim sTemp
' Use the URL of the text file you wish to retrieve:
WinHttpReq.Open "GET", " False
WinHttpReq.Send
If (WinHttpReq.Status = 200) Then
sTemp = WinHttpReq.ResponseText
' Replace any carriage returns and linefeeds with spaces
sTemp = Replace(sTemp, vbCr, " ")
sTemp = Replace(sTemp, vbLf, " ")
WebText = sTemp
' msgbox(webtext)
'Create the 'weather' file
Set objFile = objFSO.OpenTextFile("C:\Weather\Weather.txt", 8, True)
objFile.WriteLine sTemp
objFile.Close
Set objFile = Noth
Else
' Failed -- return empty string
WebText = ""
End If
How can I get it to do what I want? How do you basically parse the XML to get a file without all those markup characters?
This is the format of the file I get:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rss version="2.0" xmlns:yweather=" xmlns:geo=" <channel>
<title>Yahoo! Weather - Road Town, VI</title>
<link> <description>Yahoo! Weather for Road Town, VI</description>
<language>en-us</language>
<lastBuildDate>Fri, 23 Feb 2007 10:53 am LST</lastBuildDate>
<ttl>60</ttl>
<yweather:location city="Road Town" region="" country="VI" />
<yweather:units temperature="F" distance="mi" pressure="in" speed="mph" />
<yweather:wind chill="82" direction="140" speed="13" />
<yweather:atmosphere humidity="62" visibility="1609" pressure="30.02" rising="0" />
<yweather:astronomy sunrise="6:43 am" sunset="6:24 pm" />
<image>
<title>Yahoo! Weather</title>
<width>142</width>
<height>18</height>
<link> <url> </image>
<item>
<title>Conditions for Road Town, VI at 10:53 am LST</title>
<geo:lat>18.43</geo:lat>
<geo:long>-64.63</geo:long>
<link> <pubDate>Fri, 23 Feb 2007 10:53 am LST</pubDate>
<yweather:condition text="Fair" code="34" temp="82" date="Fri, 23 Feb 2007 10:53 am LST" />
<description><![CDATA[
<img src=" /><br />
<b>Current Conditions:</b><br />
Fair, 82 F<BR /><BR />
<b>Forecast:</b><BR />
Fri - Scattered Showers. High: 83 Low: 75<br />
Sat - PM Showers. High: 84 Low: 76<br />
<br />
<a href=" Forecast at Yahoo! Weather</a><BR/>
(provided by The Weather Channel)<br/>
]]></description>
<yweather:forecast day="Fri" date="23 Feb 2007" low="75" high="83" text="Scattered Showers" code="39" />
<yweather:forecast day="Sat" date="24 Feb 2007" low="76" high="84" text="PM Showers" code="39" />
<guid isPermaLink="false">VIXX0001_2007_02_23_10_53_LST</guid>
</item>
</channel>
</rss>
<!-- p3.weather.re3.yahoo.com uncompressed/chunked Fri Feb 23 07:12:02 PST 2007 -->
I want a file like:
Road Town
Current conditions as of 4:53 pm
Fair
83
29.96 in and rising
62%
10 mi
67
6:43
6:24
Can anyone point me in the right direction? I do not really understand VB much less VBscript....
I am able to use vbscript to query the yahoo weather service; my only problem is how to parse the XML that is downloaded. I need to get some text strings out of the XML in a certain format so that the application will know how to update based on each line of the text file,ie,:
Line1 (Place the weather is for)
Line2 (Weather condition ie, "Cloudy")
Line3 (Current Temp)
Line4 (High Temp)
Line5 (Low Temp)
etc
This is my code (which queries the XML and gets one big file):
' Retrieve the information over the web, using the WinHttp object
Dim WinHttpReq
Set WinHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")
Dim sTemp
' Use the URL of the text file you wish to retrieve:
WinHttpReq.Open "GET", " False
WinHttpReq.Send
If (WinHttpReq.Status = 200) Then
sTemp = WinHttpReq.ResponseText
' Replace any carriage returns and linefeeds with spaces
sTemp = Replace(sTemp, vbCr, " ")
sTemp = Replace(sTemp, vbLf, " ")
WebText = sTemp
' msgbox(webtext)
'Create the 'weather' file
Set objFile = objFSO.OpenTextFile("C:\Weather\Weather.txt", 8, True)
objFile.WriteLine sTemp
objFile.Close
Set objFile = Noth
Else
' Failed -- return empty string
WebText = ""
End If
How can I get it to do what I want? How do you basically parse the XML to get a file without all those markup characters?
This is the format of the file I get:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rss version="2.0" xmlns:yweather=" xmlns:geo=" <channel>
<title>Yahoo! Weather - Road Town, VI</title>
<link> <description>Yahoo! Weather for Road Town, VI</description>
<language>en-us</language>
<lastBuildDate>Fri, 23 Feb 2007 10:53 am LST</lastBuildDate>
<ttl>60</ttl>
<yweather:location city="Road Town" region="" country="VI" />
<yweather:units temperature="F" distance="mi" pressure="in" speed="mph" />
<yweather:wind chill="82" direction="140" speed="13" />
<yweather:atmosphere humidity="62" visibility="1609" pressure="30.02" rising="0" />
<yweather:astronomy sunrise="6:43 am" sunset="6:24 pm" />
<image>
<title>Yahoo! Weather</title>
<width>142</width>
<height>18</height>
<link> <url> </image>
<item>
<title>Conditions for Road Town, VI at 10:53 am LST</title>
<geo:lat>18.43</geo:lat>
<geo:long>-64.63</geo:long>
<link> <pubDate>Fri, 23 Feb 2007 10:53 am LST</pubDate>
<yweather:condition text="Fair" code="34" temp="82" date="Fri, 23 Feb 2007 10:53 am LST" />
<description><![CDATA[
<img src=" /><br />
<b>Current Conditions:</b><br />
Fair, 82 F<BR /><BR />
<b>Forecast:</b><BR />
Fri - Scattered Showers. High: 83 Low: 75<br />
Sat - PM Showers. High: 84 Low: 76<br />
<br />
<a href=" Forecast at Yahoo! Weather</a><BR/>
(provided by The Weather Channel)<br/>
]]></description>
<yweather:forecast day="Fri" date="23 Feb 2007" low="75" high="83" text="Scattered Showers" code="39" />
<yweather:forecast day="Sat" date="24 Feb 2007" low="76" high="84" text="PM Showers" code="39" />
<guid isPermaLink="false">VIXX0001_2007_02_23_10_53_LST</guid>
</item>
</channel>
</rss>
<!-- p3.weather.re3.yahoo.com uncompressed/chunked Fri Feb 23 07:12:02 PST 2007 -->
I want a file like:
Road Town
Current conditions as of 4:53 pm
Fair
83
29.96 in and rising
62%
10 mi
67
6:43
6:24
Can anyone point me in the right direction? I do not really understand VB much less VBscript....