robhunter Posted June 19, 2011 Posted June 19, 2011 (edited) Hi, I'm developing an automation script for capturing some data from an URL. But I have two questions, 1: How do I set the script, to never stop. I need it to run on XX minutes (at 00:03, when it finish, then wait until 00:18, then at 00:33... Every 15 minutes I need the script go to first line and start again.) So I pretend to run Script.exe ONE time, and it wont close until I manually close it (or crashes). 2: I need this code (see bottom of post) to run 3 times,each time some variables (marked with '!') need to have different values, I explain below what I need in this two questions. 00:03 Script starts loop 1 with this values $seccion = "SECTOR1" $url = "URL1" 00:0X Script finish loop 1 and starts loop 2 $seccion = "SECTOR2" $url = "URL2" 00:0X Script finish loop 2 and starts loop 3 $seccion = "SECTOR3" $url = "URL3" 00:0X Script finish loop 3 and wait until 00:18. 00:18 Script starts loop 1..... and so on. I have been programming autoit for 4 days and I'm pretty newbie so if you could help me with some functions and stuff for do what I want it will be great. expandcollapse popupOpt("WinWaitDelay",200) ; TIEMPO DE ESPERA ENTRE LA CARGA DE LA VENTANA Y SIGUIENTE LINEA Opt("WinDetectHiddenText",0) ; NO DETECTAMOS TEXTO OCULTO (evitamos fallos) Opt("MouseCoordMode",0) ; COORDENADAS RELATIVAS A LAS VENTANAS Opt("SendKeyDelay",20) ; PAUSAMOS MEDIO SEGUNDO ENTRE PULSACIONES (evitamos fallos) $min=@MIN $sec=@SEC ;!!!!!! VARIABLES THAT MUST CHANGE !!!!!!! Global $url = "URL1" ;!!! Global $seccion = "SECTOR1" ;!!! Global $aFile _FileReadToArray("E:\PAS_15.txt", $aFile) Func _WinWaitActivate($title,$text,$timeout=0) WinWait($title,$text,$timeout) If Not WinActive($title,$text) Then WinActivate($title,$text) WinWaitActive($title,$text,$timeout) EndFunc If $min="00" or $min="15" or $min="30" or $min="45" Then Sleep(180000) EndIf #region ; RECOGIDA DE DATOS DE LAS METRICAS Run(@ProgramFilesDir & "\Mozilla Firefox\firefox.exe http://XXXX/page.php?id=" & $url) _WinWaitActivate("Monitors - Mozilla Firefox","") Send("^a") Send("^c") $actividad = ClipGet() WinClose("Monitors - Mozilla Firefox","") ;METEMOS LOS DATOS EN UN TXT $fAprobadas = FileOpen("E:\PAS_15.txt",2) FileWrite($fAprobadas, $actividad) FileClose($fAprobadas) #endregion #region ; FILTRADO DE DATOS EN NOTEPAD Select Case $min >= "00" And $min <= "14" _Go(46, 00) Case $min >= "15" And $min <= "29" _Go(01, 15) Case $min >= "30" And $min <= "44" _Go(16, 30) Case $min >= "45" And $min <= "59" _Go(31, 45) EndSelect Func _Go($start, $end) For $i = 5 To $aFile[0] $atemp = StringRegExp($aFile[$i], "\.(\d{2})\s.+", 1) If $end = 00 Then If $atemp[0] >= $start And $atemp[0] <= 59 Or $atemp[0] = $end Then $fOpen = FileOpen("E:\PAS_15_" & $seccion & ".txt",1) FileWriteLine($fOpen, $aFile[$i] & @CRLF) FileClose($fOpen) EndIf Else If $atemp[0] >= $start And $atemp[0] <= $end Then $fOpen = FileOpen("E:\PAS_15_" & $seccion & ".txt",1) FileWriteLine($fOpen, $aFile[$i] & @CRLF) FileClose($fOpen) EndIf EndIf Next EndFunc #endregion ; ABRIMOS EL EXCEL E INSERTAMOS LOS VALORES actividad() Edited June 19, 2011 by robhunter
PsaltyDS Posted June 19, 2011 Posted June 19, 2011 Try this basic structure: HotKeySet("{ESC}", "_Quit") ; Need a way to exit the script Global $iSelect = 0 Global $aSections[3] = ["Section_0", "Section_1", "Section_2"] Global $aURLs[3] = ["http://www.autoitscript.com", "http://www.libreoffice.org", "http://www.mozilla.com"] While 1 Switch @SEC Case 03, 18, 33, 48 ; Every 15 seconds $sSection = $aSections[$iSelect] $sURL = $aURLs[$iSelect] $iSelect += 1 If $iSelect > UBound($aSections) - 1 Then $iSelect = 0 ; Replace this code with what you really want done ConsoleWrite("Time = " & @HOUR & ":" & @MIN & ":" & @SEC & "; Section = " & $sSection & "; URL = " & $sURL & @LF) EndSwitch Sleep(1000) WEnd Func _Quit() Exit EndFunc ;==>_Quit This fires on the matching seconds (@SEC) instead of minutes for the sake of testing, but you get the idea. It loops with While/WEnd. It uses an index variable ($iSelect) to cycle through the choices from arrays. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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