Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript to copy XML sheet/info and save it. 1

Status
Not open for further replies.

ErrorLINE1CHAR1

Programmer
Dec 3, 2010
24
US
So here is the problem..

I have a script to get the XML sheet from Y! weather
the problem is that the only browser that saves the XML sheet properly is Google Chrome, it actually views the XML markup on the webpage and CTRL+S will give me save as and i just save that XML sheet manually then my app has no problem updating the weather info.

BUT this app is for a group with no permissions to set GC as the default browser let alone install it to the computer.

SO Google Chrome is on the groups PC's in portable format,
but if i create the script for them and try to have it follow the path to Google chrome McAfee Deletes is as soon as you save the file as .vbs . . . and I dont want to spend any more time to write this to a Function and have it Window_OnLoad, as well as iTimerID.

this is the code i have but its only opening it in IE which displays it in RSS Feed format and does not do the job. . .

in the apps main code i used iTimerID to re-run this script every 1.5 hrs (assuming that Y! has updated the weather info by that time. . .)

Code:
Set yXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0")

	yXMLHTTP.Open "GET", "[URL unfurl="true"]http://weather.yahooapis.com/forecastrss?w=12798480&u=f.xml",False[/URL]
	yXMLHTTP.Send

		If yXMLHTTP.Status = 200 Then
	 		Set yStream = CreateObject("ADODB.Stream")
	 			yStream.Open
	 			yStream.Type = 1
	 			yStream.Write yXMLHTTP.responseBody
	 			yStream.SaveToFile "F:\WeatherCast\97124.xml"
	 			yStream.Close

		End If

So as of now that does not work.. any one know a work around to have it GET the ACTUAL XML form not FEED form? (and yes i use y to remind me that its info from Yahoo! :p )

Devon
Intel Corp. (HF)
 
OK wait... i just got hit in the face.. correct me if im wrong but the
Code:
yStream.SaveToFile "F:\WeatherCast\97124.xml"

is auto pressing ctrl+s right?

well i just went to manually do it via IE i pressed ctrl+S and got the error sound.. BUT file Save As is there.. so how would i do that? like this:
Code:
WScript.sendkeys %f
WScript.sendkeys a
WScript.sendkeys {enter}
WScript.sendkeys {TAB}
WScript.sendkeys {enter}

would this work? i cant tell cause weather has not updated :/

but if it would am i just be retorical by going the route of GET HTTP and i could just use the?:
Code:
WScript.createobject("InternetExplorer.application")

Devon
Intel Corp. (HF)
 
I tried it :
Code:
Set objIE = CreateObject("InternetExplorer.Application","IE_")
Wscript.Sleep 1000
objIE.Visible = 0
objIE.Navigate("[URL unfurl="true"]http://weather.yahooapis.com/forecastrss?w=12798480&u=f.xml")[/URL]
WScript.Sleep 2000
WshShell.sendkeys %
'WScript.sleep 500
WshShell.sendkeys f
WScript.sleep 500
WshShell.sendkeys a
WScript.sleep 500
WshShell.sendkeys {ENTER}
WScript.sleep 500
WshShell.sendkeys {TAB}
WScript.sleep 500
WshShell.sendkeys {ENTER}
WScript.Sleep 500

Sub ojbIE_onQuit()
   Wscript.Quit
End Sub

and the answer is no >:[ go figure. . . i should have thought that IE would not support sendkeys. . .
and other thoughts still?

Devon
Intel Corp. (HF)
 
[0] Chrome saves to rss feed as well. It would be the same if you open in IE.

[1] The list in the op does not open the feed in IE and that's the point. The repetitive description of "do the job" and "not do the job" is devoid of meaning.

[3]You never need to use sendkeys to "do the job".

[4] This would be error (from the 2nd execution onward or if the file already exists at the first execution.)
[tt]> [/tt]yStream.SaveToFile "F:\WeatherCast\97124.xml"
[tt] yStream.SaveToFile "F:\WeatherCast\97124.xml"[red],2[/red] 'adSaveCreateOverWrite=2[/tt]
 
OMG Really! thats all i forgot!!
haha thank you so much agian Tsuji!! your the master! and yes it works!!

the funny thing is if it put the update script into the main of the application McAfee will auto delete? oh well the script alone works just fine :D i will post it here so if anyone ever wants to do the same they can!!

Where the are blanks create your own DIM name for the elements on the XML sheet, as well as adding the names for the yweather:NAME, and the element id in the other blank :)

Main Body for HTA:
Code:
<html>

<head>
	<Title> y!Wet RC3</Title>
<META http-equiv="Content-Script-Type" content="TEXT/VBScript">

<script type="text/vbscript" src="update97124.vbs"> </script>

<script type="text/vbscript">
Dim objShell

Set objShell = CreateObject("WScript.Shell")
objShell.exec("cscript F:\WeatherCast\update97124.vbs")

</script>

<script type="text/vbscript">

SUB Window_OnLoad

	window.resizeTo 500,500
	
END SUB

DIM yXML
DIM strXMLFile
DIM yWetCity
DIM yWetState
DIM weatherCondition
DIM currTemp
DIM highTemp
DIM lowTemp
DIM ChillWind
DIM LUPD





'On Error Resume Next

strXMLFile = "F:\WeatherCast\97124.xml"
SET yXML = CreateObject("Microsoft.XMLDOM")
yXML.async = "False"
yXML.load(strXMLFile)

				=	yXML.getElementsByTagName("yweather:").item(0).attributes.getNamedItem("").value
				=	yXML.getElementsByTagName("yweather:").item(0).attributes.getNamedItem("").value
				=	yXML.getElementsByTagName("yweather:").item(0).attributes.getNamedItem("").value
				=	yXML.getElementsByTagName("yweather:").item(0).attributes.getNamedItem("").value
LUPD				=	yXML.getElementsByTagName("yweather:condition").item(0).attributes.getNamedItem("date").value
yWetCity 			= 	yXML.getElementsByTagName("yweather:location").item(0).attributes.getNamedItem("city").value
yWetState			= 	yXML.getElementsByTagName("yweather:location").item(0).attributes.getNamedItem("region").value
weatherCondition 	= 	yXML.getElementsByTagName("yweather:condition").item(0).attributes.getNamedItem("text").value
currTemp 			= 	yXML.getElementsByTagName("yweather:condition").item(0).attributes.getNamedItem("temp").value
highTemp			= 	yXML.getElementsByTagName("yweather:forecast").item(0).attributes.getNamedItem("high").value
lowTemp 			= 	yXML.getElementsByTagName("yweather:forecast").item(0).attributes.getNamedItem("low").value
ChillWind 			= 	yXML.getElementsByTagName("yweather:wind").item(0).attributes.getNamedItem("chill").value

document.write ("Last update: ") & LUPD & ("<br />")
document.write ("Location: ") & ywetcity & ", " & yWetState & ("<br />")  
document.write ("Current Conditions: ") & weatherCondition & ("<br /> Current Temp: ") & currTemp & ("<br /> High: ") & highTemp & ("<br /> Low: ") & lowTemp & ("<br />")
document.write ("Wind Chill: ") & ChillWind

</script>

</head>
<body>
<div align="center" id="CWet">
</div>
</body>
</html>

And script:
Code:
CONST adSaveCreateNotExist = 1
CONST adSaveCreateOverWrite=2

yXML = "[URL unfurl="true"]http://weather.yahooapis.com/forecastrss?w=12798480&u=f.xml"[/URL]
	
	SET yXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0")

		yXMLHTTP.Open "GET", yXML, FALSE
		yXMLHTTP.Send

			IF yXMLHTTP.Status = 200 THEN
	 			SET yStream = CreateObject("ADODB.Stream")
	 				yStream.Open
	 				yStream.Type = 1
	 				yStream.Write yXMLHTTP.responseBody
	 				yStream.SaveToFile "F:\WeatherCast\97124.xml",2
	 				yStream.Close


				SET yStream = NOTHING
				SET yXML = NOTHING

			END IF

open source!

Devon
Intel Corp. (HF)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top