MarkCheavens Posted June 10, 2010 Posted June 10, 2010 I have written a small watcher application that looks at the server time, the last modified date of a file on a web server and then "does" something if the time is too great. (The file is too old). I have attached a very stripped down version of the code. It will reliably fail when the time difference between the server date and the Last Modified date are near 5 minutes of one another. I know WHY this is: It is due to the file being updated on the server (FTP process). What I need it for my script to ignore the error and continue. I know this should be "simple", but none of my error traps have helped. Thanks in advance. Mark While 1 $url="http://www.cheavens.com/purg/webcam/camera1.jpg" $WinHttpReq = ObjCreate("winhttp.winhttprequest.5.1") $WinHttpReq.open("HEAD",$URL) $WinHttpReq.send() $headerLM = $WinHttpReq.GetResponseHeader("Last-Modified") $headerD = $WinHttpReq.GetResponseHeader("Date") ConsoleWrite("Last Modified: " & $headerLM & @CRLF ) ConsoleWrite("Server Time : " & $headerD & @CRLF & @CRLF ) Sleep(1000) WEnd
Authenticity Posted June 10, 2010 Posted June 10, 2010 Opt("MustDeclareVars", 1) HotKeySet("{ESC}", "_Quit") Local $url, $WinHttpReq, $oErr, $headerLM, $headerD $WinHttpReq = ObjCreate("winhttp.winhttprequest.5.1") $oErr = ObjEvent("AutoIt.Error", "_ErrorHandler") While 1 $url = "http://www.cheavens.com/purg/webcam/camera1.jpg" $WinHttpReq.open("HEAD",$URL) $WinHttpReq.send() $headerLM = $WinHttpReq.GetResponseHeader("Last-Modified") $headerD = $WinHttpReq.GetResponseHeader("Date") ConsoleWrite("Last Modified: " & $headerLM & @CRLF ) ConsoleWrite("Server Time : " & $headerD & @CRLF & @CRLF ) Sleep(500) WEnd Func _Quit() Exit EndFunc Func _ErrorHandler() ConsoleWrite($oErr.description & @CRLF) EndFunc Should do something like the following when failed to retrieve request response: ... Last Modified: Thu, 10 Jun 2010 21:31:25 GMT Server Time : Thu, 10 Jun 2010 21:36:41 GMT Last Modified: Thu, 10 Jun 2010 21:31:25 GMT Server Time : Thu, 10 Jun 2010 21:36:42 GMT The requested header was not found Last Modified: Server Time : Thu, 10 Jun 2010 21:36:44 GMT The requested header was not found Last Modified: Server Time : Thu, 10 Jun 2010 21:36:45 GMT Last Modified: Thu, 10 Jun 2010 21:36:45 GMT Server Time : Thu, 10 Jun 2010 21:36:46 GMT Last Modified: Thu, 10 Jun 2010 21:36:45 GMT Server Time : Thu, 10 Jun 2010 21:36:47 GMT ...
MarkCheavens Posted June 10, 2010 Author Posted June 10, 2010 Works great! The full code compares the two times and if a webcam fails to update twice (Greater than 11 minutes) then it cycles the power on the webcam. Normally the update occurs every 5 minutes, so the code that I provided was stripped down to show the heart of what it was doing. (Now I just need to spend the time to understand HOW you fixed it!) Thank you Authenticity!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now