' ---- MiniCity.vbs ----
private sub hitCity(strURL)
'---- get the XML from the minicity site -----
Set web = CreateObject( "WinHttp.WinHttpRequest.5.1" )
web.Open "GET", strURL&"xml", False
web.Send
varByteArray=web.ResponseBody
'----- save it so we can parse it later -----
Const ForReading = 1, ForWriting = 2, ForAppending = 8
strFile="temp.xml"
Set fs = CreateObject("Scripting.FileSystemObject")
Set ts = fs.OpenTextFile(strFile, ForWriting, True)
strData = ""
strBuffer = ""
For lngCounter = 0 to UBound(varByteArray)
ts.Write Chr(255 And Ascb(Midb(varByteArray,lngCounter + 1, 1)))
Next
ts.Close
'---- parse xml ----
set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("temp.xml")
highest_nodename=""
highest_text="0"
for each x in xmlDoc.documentElement.childNodes
'----------------- ADD MORE CHECKS HERE IF NEEDED ---------------------
if lcase(x.nodename)="criminality" and x.text > highest_text then
highest_nodename=x.nodename
highest_text=x.text
end if
if lcase(x.nodename)="unemployment" and x.text > highest_text then
highest_nodename=x.nodename
highest_text=x.text
end if
if lcase(x.nodename)="pollution" and x.text > highest_text then
highest_nodename=x.nodename
highest_text=x.text
end if
if lcase(x.nodename)="transport" and x.text < "100" then
highest_nodename=x.nodename
highest_text=100-x.text
end if
'msgbox(x.nodename&": "&x.text)
next
'msgbox(highest_nodename)
'---- Go to the URL required ---
dim typeofhelp
typeofhelp = ""
if lcase(highest_nodename)="criminality" then typeofhelp="sec"
if lcase(highest_nodename)="unemployment" then typeofhelp="ind"
if lcase(highest_nodename)="pollution" then typeofhelp="env"
if lcase(highest_nodename)="transport" then typeofhelp="tra"
goToURL=strURL&typeofhelp
' ---- Message box! ----
msgBox("Visting: "&goToURL)
' ---- Open the site ----
Set WshShell = WScript.CreateObject("WScript.Shell")
' ---- Choose Firefox or Internet Explorer by moving the apostrophe ----
WshShell.Run "firefox "&goToURL
'WshShell.Run "iexplore "&goToURL
' ---- delete temp file ----
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile("temp.xml")
end sub
' ---- Start Here ----
Const ForReading = 1, ForWriting = 2, ForAppending = 8
' ---- You can change the filename and location here. ----
strCityFile="minicity.txt"
Set fs2 = CreateObject("Scripting.FileSystemObject")
Set ts2 = fs2.OpenTextFile(strCityFile, 1, True)
do while not ts2.atendofstream
strCityData = ts2.readline
hitCity(strCityData)
choice=msgbox("Visit the next city?",VbOKCancel)
if choice = 2 then
WScript.Quit
end if
loop
msgbox("All done")
' ---- Time to tidy up ----
ts2.close
set ts2=nothing
set fs2=nothing