barbossa
Members-
Posts
7 -
Joined
-
Last visited
Recent Profile Visitors
204 profile views
barbossa's Achievements
Seeker (1/7)
1
Reputation
-
Gianni reacted to a post in a topic:
Read data from html Tables from raw HTML source
-
Read data from html Tables from raw HTML source
barbossa replied to Gianni's topic in AutoIt Example Scripts
Hi Chimp! Thanks a lot for your example - it saved me a lot work! I had to parse a table with almost 1400 rows (and lots of rowspans) in an 1.5MB HTML file, and got some performance issues. Here is how I solved them: First, I adapted the HTML tag position search in _ParseTags to search starting on the last tag found position, so StringInStr doesn't need to count thousands of "<tr" tags every iteration. Then, _ArraySort failed (too many rows...). So, to get the tag list pre-sorted, I search for the first opening and first closing tag. If the opening is before the closing, write to $aThisTagsPositions and find the next opening; if the closing is before the next opening, write to $aThisTagsPositions and find the next closing. This made it possible to read that huge HTML file in less than 90 seconds. Just replace the code on lines 208-216 with this: Local $iNextOpenPosition = StringInStr($sHtml, $sOpening, 0, 1) Local $iNextClosePosition = StringInStr($sHtml, $sClosing, 0, 1) Local $iOpenCount = 1 ; 2) find in the HTML the positions of the $sOpening <tag and $sClosing </tag> tags For $i = 1 To $iNrOfThisTag * 2 ;search all the opening and closing tags If ($iNextOpenPosition < $iNextClosePosition) And $iNextOpenPosition <> 0 Then $aThisTagsPositions[$i][0] = $iNextOpenPosition $aThisTagsPositions[$i][1] = $sOpening ; it marks which kind of tag is this $aThisTagsPositions[$i][2] = $iOpenCount; nr of this tag $iOpenCount += 1 $iNextOpenPosition = StringInStr($sHtml, $sOpening, 0, 1, $aThisTagsPositions[$i][0] + 1) Else $aThisTagsPositions[$i][0] = $iNextClosePosition + StringLen($sClosing) - 1 $aThisTagsPositions[$i][1] = $sClosing ; it marks which kind of tag is this $iNextClosePosition = StringInStr($sHtml, $sClosing, 0, 1, $aThisTagsPositions[$i][0] + 1) EndIf Next -
Tekk, probably that, tested it too and the compiled .exe worked fine... jdelany, well done!
-
As I said in the first post, I was just playing around the possibility, I don't think it would have any practical application, and would definitely be horrendous to maintain. BrewManNH, look at the 1-sized example I posted after. It has 5 dimensions, and holds only one value (the number of values would be 1^5 = 1). The first example has 32 zeros, filling the entire array (2^5 = 32).
-
That is the problem: the brackets ARE correct. Try running this: Dim $arTest[1][1][1][1][1] = [[[[[1]]]]]
-
Hi! I was messing around with AutoIT, and found I can't initialize a 5D array. I re-checked the square brackets countless times, but AutoIT keeps returning "ERROR: wrong nesting in initializer". 4D arrays work fine. Here is the example: Local $arTestOk[2][2][2][2] = [[[[0,0],[0,0]],[[0,0],[0,0]]],[[[0,0],[0,0]],[[0,0],[0,0]]]] Local $arTestBad[2][2][2][2][2] = [[[[[0,0],[0,0]],[[0,0],[0,0]]],[[[0,0],[0,0]],[[0,0],[0,0]]]],[[[[0,0],[0,0]],[[0,0],[0,0]]],[[[0,0],[0,0]],[[0,0],[0,0]]]]] Is this a bug with AutoIT?
-
I think most people that use portable USB drives have this problem: the shortcuts to your portable apps get messed up whenever the drive letter changes. I made this small (and hopefully useful) script to deal with the problem. It generates and compiles an AutoIT Script that calls your app with the relative paths inside your drive, also passing any command line parameter (for example, drag&dropping files on the shortcut) to the portable application. It has no GUI, only two Open File dialogs, one for you to choose your executable, and other for choosing the shortcut icon, automatically extracted from the executable file using the ExtractIconToFile UDF. Since the script uses AutoIT itself to compile the shortcut, you must also place Aut2exe.exe, AutoItSC.bin and upx.exe on the script folder. If you find any bugs, corrections or suggestions, please let me know. Here is the code for the shortcut creator: #include <WinAPI.au3> #include "ExtractIconToFile.au3" Dim $exeFilePath Dim $icoFilePath Dim $tmpFolderPath Dim $fileHandle, $filename Dim $numIcons Dim $i ;choose .exe file $exeFilePath = FileOpenDialog ("Choose your destiny... I mean, your app", StringMid(@ScriptDir, 1, 3), "Executable Files (*.exe)", 3) If @error <> 1 Then $tmpFolderPath = @ScriptDir & "\tmp_portable_app_" & @YEAR & @MON & @MDAY & @HOUR & @MIN DirCreate ($tmpFolderPath) ;extract icon files $numIcons = _WinAPI_ExtractIconEx($exeFilePath, -1, 0, 0, 0) For $i = 1 To $numIcons $filename = $tmpFolderPath & "\icon_" & $i & ".ico" _ExtractIconToFile($exeFilePath, $i, $filename) Next $icoFilePath = FileOpenDialog ("Choose your shortcut icon", $tmpFolderPath, "Icon files (*.ico)", 3) If @error <> 1 Then $fileHandle = FileOpen ($tmpFolderPath & "\tmp_portable_app.au3", 1) ;generates autoit code to run the application ;Run (@ScriptDir & "\_Portable Apps Folder\MyApp\MyApp.exe " & $CmdLineRaw) FileWriteLine ($fileHandle, 'Run (@ScriptDir & "' & StringMid($exeFilePath, 3) & ' " & $CmdLineRaw)') FileClose ($fileHandle) ;compiles the script to a .exe file, with the same name as the portable app .exe ;on the drive root of where the script is run, with the chosen icon RunWait (@ScriptDir & '\aut2exe.exe' & _ ' /in "' & $tmpFolderPath & '\tmp_portable_app.au3 ' & '"' & _ ' /out "' & StringMid(@ScriptDir, 1, 3) & StringMid($exeFilePath, StringInStr($exeFilePath, '\', Default, -1)) & '"' & _ ' /icon "' & $icoFilePath & '"') ;removes temporary folder DirRemove ($tmpFolderPath, 1) EndIf EndIf
-
This is a simple implementation of an ABX Test for audio files. In short, you get the same audio file encoded with different bitrates/methods/codecs to check if you can spot differences between them. I tried to find some Windows software to do this (to check how good is my hearing/new headphones), but couldn't find any, so I made one myself Features include: - support for all audio formats supported by your system ;-) - simple seek bar - (poorly) synched samples If you find any bugs, corrections or suggestions, please let me know. Here is the code: #Region declarations #NoTrayIcon #include <Sound.au3> #include <EditConstants.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GUIEdit.au3> #Include <GuiSlider.au3> ;options Opt("GUIOnEventMode", 1) ;state variables Dim $GUIShowing = 0 Dim $bFileAValid = False Dim $bFileBValid = False Dim $fileAPath Dim $fileBPath Dim $fileAHandle Dim $fileBHandle Dim $fileXHandle Dim $playingFile = 0 Dim $numTests = 0 Dim $testHistory[51][2];50 tests, 0 is real X, 1 is guessed X ;definitions for setup GUI Dim $GUIMain = GUICreate ("ABX test setup", 640, 140) Dim $inputFileA = GUICtrlCreateInput("File A", 20, 20, 500, Default, 0x0800) Dim $buttonOpenFileA = GUICtrlCreateButton ("Open...", 530, 20, 90, Default) Dim $inputFileB = GUICtrlCreateInput("File B", 20, 60, 500, Default, 0x0800) Dim $buttonOpenFileB = GUICtrlCreateButton ("Open...", 530, 60, 90, Default) Dim $labelFileAOK = GUICtrlCreateLabel ("File A invalid", 20, 100, 100, Default) Dim $labelFileBOK = GUICtrlCreateLabel ("File B invalid", 120, 100, 100, Default) Dim $buttonStart = GUICtrlCreateButton ("Start test", 520, 100, 100, Default) Dim $buttonAbout = GUICtrlCreateButton ("About...", 400, 100, 100, Default) GUICtrlSetOnEvent ($buttonOpenFileA, "OpenFileA") GUICtrlSetOnEvent ($buttonOpenFileB, "OpenFileB") GuiCtrlSetOnEvent ($buttonStart, "StartTest") GuiCtrlSetOnEvent ($buttonAbout, "AboutBox") GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") Dim $GUITest = GUICreate ("ABX test", 260, 300) Dim $soundPosition = GUICtrlCreateSlider(16, 112, 225, 33) Dim $buttonPlayA = GUICtrlCreateButton("Play A", 16, 32, 65, 65) Dim $buttonPlayB = GUICtrlCreateButton("Play B", 96, 32, 65, 65) Dim $buttonPlayX = GUICtrlCreateButton("Play X", 176, 32, 65, 65) Dim $labelTestNumber = GUICtrlCreateLabel("Test Number:", 16, 8, 68, 17) Dim $buttonXisA = GUICtrlCreateButton("X is A", 56, 152, 65, 65) Dim $buttonXisB = GUICtrlCreateButton("X is B", 136, 152, 65, 65) Dim $buttonStopSound = GUICtrlCreateButton("STOP SOUND", 16, 216, 225, 33) Dim $buttonEndTest = GUICtrlCreateButton("END TEST", 16, 256, 225, 33) GUICtrlSetOnEvent ($buttonPlayA, "PlayA") GUICtrlSetOnEvent ($buttonPlayB, "PlayB") GUICtrlSetOnEvent ($buttonPlayX, "PlayX") GuiCtrlSetOnEvent ($soundPosition, "SeekSound") GuiCtrlSetOnEvent ($buttonStopSound, "StopSound") GuiCtrlSetOnEvent ($buttonEndTest, "EndTests") GuiCtrlSetOnEvent ($buttonXisA, "XisA") GuiCtrlSetOnEvent ($buttonXisB, "XisB") GuiCtrlSetOnEvent ($buttonEndTest, "EndTests") GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") Dim $GUIresults = GUICreate("Test results", 330, 440) Dim $textResults = GUICtrlCreateEdit("", 8, 8, 313, 417, BitOR($GUI_SS_DEFAULT_EDIT,$ES_READONLY)) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") #endregion declarations #region Main Loop GUISwitch($GUIMain) GUISetState(@SW_SHOW) While True Sleep (1000) Switch $GUIShowing Case 0 If $bFileAValid Then GUICtrlSetData($labelFileAOK, "File A VALID") Else GUICtrlSetData($labelFileAOK, "File A invalid") EndIf If $bFileBValid Then GUICtrlSetData($labelFileBOK, "File B VALID") Else GUICtrlSetData($labelFileBOK, "File B invalid") EndIf Case 1 If _SoundStatus($playingFile) = "playing" Then GUICtrlSetData($soundPosition, Ceiling((_SoundPos($playingFile, 2) / _SoundLength($playingFile, 2)) * 100)) EndIf EndSwitch WEnd #endregion Main Loop #region Functions Func CLOSEClicked() MsgBox(64, "Exit", "Exiting...", 2) Exit EndFunc Func OpenFileA () $fileAPath = FileOpenDialog ("Audio file A", Default, "Audio Files (*.mp3;*.wav;*.flac)", 3) If @error <> 1 Then _GUICtrlEdit_SetText($inputFileA, $fileAPath) $fileAHandle = _SoundOpen($fileAPath) If @error <> 0 Then MsgBox(16, "Error", "Error loading the file.", 0, $GUIMain) $bFileAValid = False Else MsgBox(64, "OK", "File loaded successfully.", 0, $GUIMain) $bFileAValid = True EndIf Else MsgBox(16, "Error", "Error opening the file.", 0, $GUIMain) EndIf EndFunc Func OpenFileB () $fileBPath = FileOpenDialog ("Audio file B", Default, "Audio Files (*.mp3;*.wav;*.flac)", 3) If @error <> 1 Then _GUICtrlEdit_SetText($inputFileB, $fileBPath) $fileBHandle = _SoundOpen($fileBPath) If @error <> 0 Then MsgBox(16, "Error", "Error loading the file.", 0, $GUIMain) $bFileBValid = False Else MsgBox(64, "OK", "File loaded successfully.", 0, $GUIMain) $bFileBValid = True EndIf Else MsgBox(16, "Error", "Error opening the file.", 0, $GUIMain) EndIf EndFunc Func StartTest () If $bFileAValid And $bFileBValid Then GUISetState(@SW_HIDE) GUISwitch($GUITest) GUISetState(@SW_SHOW) $GUIShowing = 1 NewTest() Else MsgBox (16, "Error", "Both files must be valid.", 0, $GUIMain) EndIf EndFunc Func PlayA () _SoundPause($playingFile) $playingFile = $fileAHandle SeekSound () EndFunc Func PlayB () _SoundPause($playingFile) $playingFile = $fileBHandle SeekSound () EndFunc Func PlayX () _SoundPause($playingFile) $playingFile = $fileXHandle SeekSound () EndFunc Func SeekSound () Dim $hour, $minute, $second Dim $percent Dim $time_in_seconds $percent = _GUICtrlSlider_GetPos($soundPosition) $time_in_seconds = Floor((_SoundLength($playingFile, 2) / 1000) * ($percent / 100)) $hour = Floor($time_in_seconds/3600) $time_in_seconds = Mod($time_in_seconds, 3600) $minute = Floor($time_in_seconds/60) $time_in_seconds = Mod($time_in_seconds, 60) $second = $time_in_seconds _SoundSeek($playingFile, $hour, $minute, $second) _SoundPLay($playingFile) EndFunc Func StopSound () _SoundStop($playingFile) EndFunc Func XisA () $testHistory[$numTests][1] = "A" NewTest() EndFunc Func XisB () $testHistory[$numTests][1] = "B" NewTest() EndFunc Func AboutBox () MsgBox(0, "About ABX tester", _ "Implement ABX double blind test for different quality settings audio files." & @CRLF & _ "The test consists of a number of trials in wich the test subject must listen" & @CRLF & _ "to two audio samples (A and B) and compare them to one of them, randomly" & @CRLF & _ "assigned to X. For a minimum of 16 tests, if the subject chooses the correct" & @CRLF & _ "file less than 95% of the time, then the null hypothesis (there is no signi-" & @CRLF & _ "ficant difference between A and B) cannot be rejected." & @CRLF & _ "" _ , 0, $GUIMain) EndFunc Func EndTests() Dim $i Dim $totalRight = 0 Dim $tmpData GUISetState(@SW_HIDE) GUISwitch($GUIresults) GUISetState(@SW_SHOW) $GUIShowing = 2 For $i = 1 to $numTests If $testHistory[$i][1] <> "" Then $tmpData = $tmpData & "Test " & StringFormat("%02d", $i) & ": X was " & _ $testHistory[$i][0] & ", your answer was " & _ $testHistory[$i][1] & @CRLF If $testHistory[$i][0] = $testHistory[$i][1] Then $totalRight += 1 EndIf EndIf Next $tmpData = $tmpData & "Total right: " & $totalRight & " (" & Round(($totalRight/$numTests)*100, 2) & "%)" GuiCtrlSetData($textResults, $tmpData) EndFunc ;randomly assigns file A or B to X Func SetFileX () Dim $i $i = Random (1, 2, 1) If $i = 1 Then $fileXHandle = $fileAHandle $testHistory[$numTests][0] = "A" Else $fileXHandle = $fileBHandle $testHistory[$numTests][0] = "B" EndIf EndFunc Func NewTest () If $numTests < 50 Then $numTests += 1 MsgBox(64, "Setting X", "Test " & $numTests & @CRLF & "setting file X...", 2, $GUITest) SetFileX() GUICtrlSetData($labelTestNumber, $numTests) StopSound() Else EndTests() EndIf EndFunc #endregion Functions