Friday 20 June 2008

update local website with live info

problem: customers stock system doesnt play nice with web, so stock levels and prices are manually updated each morning. local copy of website on sales laptops information can be out by two weeks!

what im not doing: calling in sales reps every day to get up-to-date info


so, vbs to the rescue again. as this is a text file, read into an array by php live it is uploaded using ftp binary type to preserve carriage returns. downloading via ascii should preserve this file characteristic.

on error resume next
url = "onlinepathhere"
path = "localpathhere"
Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
xmlhttp.open "GET", url, False
xmlhttp.send()
if xmlhttp.Status = 200 then 'if status is anything other than 200 it is not ready
Set fstemp = CreateObject("Scripting.FileSystemObject")
fstemp.GetFile(path + "pricelist.bak").Delete 'on error statement ensure script carries on if file doesnt exist
fstemp.MoveFile path + "pricelist.dat", path + "pricelist.bak"
Set filetemp = fstemp.CreateTextFile(path + "pricelist", true)
filetemp.write (xmlhttp.responseText)
filetemp.close
else
msgbox "please ensure that you are connected to the internet to update stock figures" + vbcrlf + vbcrlf + "if you are connected please try again later"
end if
wscript.quit()

No comments: