Cormin Posted August 5, 2018 Posted August 5, 2018 (edited) I cant figure out why my FileReadLine keeps returning nothing? My script just keeps adding and looping the line count. This is a part of my download function which downloads an html page to txt. Then my parse function tries to read through it and grab the info it wants. The _FileCountLines returns the correct number of lines. The fact that that works really makes it hard to understand why filereadline doesnt work. Local $tempfile = _TempFile(@TempDir,"",".txt") Local $hDownload = InetGet($url, $tempfile, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND) Do Sleep(250) Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE) InetClose($hDownload) sleep(100) $totallines = _FileCountLines($tempfile) sleep(500) Local $hFileOpen = FileOpen($tempfile,2) If $hFileOpen = -1 Then FileDelete($tempfile) exit EndIf expandcollapse popupFunc parse() while 1 $read = FileReadLine($tempfile, $readline) while 1 $ttmessage = "parsing2 " & $readline & @CRLF & $read & @CRLF & $readedit tt() $read = FileReadLine($tempfile, $readline) if Stringinstr($read, 'd=desc">Download</a>') = 1 Then;finds chunk of hacks ExitLoop Else $readline = $readline + 1 if $readline > $totallines Then $readline = 1 EndIf ContinueLoop EndIf WEnd if Stringinstr($read, '<td class="cell') = 1 Then;finds hack cells $readline = $readline + 1;skips to next line where data is $read = FileReadLine( $tempfile, $readline);grabs data if $classcounter = 1 Then;name parsename() EndIf if $classcounter = 2 Then;demo parsedemo() EndIf if $classcounter = 3 Then;featured parsefeatured() EndIf if $classcounter = 4 Then;exit count parseexitcount() EndIf if $classcounter = 5 then;difficulty parsedifficulty() EndIf if $classcounter = 6 then;author parseauthor() EndIf if $classcounter = 7 then;rating parserating() EndIf if $classcounter = 8 then;file size parsefilesize() EndIf if $classcounter = 9 then;download link parsedownloadlink() $classcounter = 1 EndIf $classcounter = $classcounter + 1 EndIf if Stringinstr($read, 'downloads</span>') = 1 Then;finds last hack cell $classcounter = 1 EndIf if Stringinstr($read, '</html>') = 1 Then;finds last line in html page $readline = 1 if $currentpage < $maxpages Then Else $currentpage = $currentpage + 1 EndIf ExitLoop Else if $readline > $totallines Then $readline = 1 EndIf $readline = $readline + 1 ContinueLoop EndIf WEnd EndFunc Edited August 5, 2018 by Cormin
TheXman Posted August 5, 2018 Posted August 5, 2018 (edited) Your problem is most likely the line below: Local $hFileOpen = FileOpen($tempfile,2) Why are you opening a file that you want to read in OVERWRITE mode? That basically erases any content it may have held. That's one of the problems with using magic number literals instead of named constants. If you would have used the named constant for "2", you would have seen that it is "$FO_OVERWRITE (2) = Write mode (erase previous contents)" and most likely have seen your error. You obviously want " $FO_READ (0) = Read mode (default) ". In this specific case, you don't even need the second parameter because it will default to read mode. Edited August 5, 2018 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
Cormin Posted August 5, 2018 Author Posted August 5, 2018 (edited) @thexman That was just me trying something different, I had it as 0 at first. I put it back to 0 and retested, still same result Edited August 5, 2018 by Cormin
TheXman Posted August 5, 2018 Posted August 5, 2018 According to the help file for FileReadLine: If a filename is passed to the function, the file will be opened and closed during the call which slows execution considerably, particularly when reading multiple lines. Furthermore, because the file is closed after each call, there is no automatic "next" line increase and the "line" parameter must be used when reading lines in a loop. Note that this will further slow execution as AutoIt re-reads the file each time. CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
Cormin Posted August 5, 2018 Author Posted August 5, 2018 (edited) @TheXman I just replaced every read line with this and still same result $hFileOpen = FileOpen($tempfile,0) $read = FileReadLine($hFileOpen, $readline) Even tried this and same result $read = FileReadLine(FileOpen($tempfile), $readline) Edited August 5, 2018 by Cormin
TheXman Posted August 5, 2018 Posted August 5, 2018 It's hard to tell what the issue may be with snippets of the code. The problem could be anywhere. Can you supply testable code or the actual script? CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
Cormin Posted August 5, 2018 Author Posted August 5, 2018 (edited) Yeah I guess I'll post the entire script. I was hesitant because in the past Ive been wrongly accused of writing scripts to give an advantage in a game where all it did was parse the mario maker bookmark site for twitch chat(the mods told me they didnt know what twitch was yet they still dinged me)... Either way what this script does it parse smwcentral (smw romhack website) to gather a database of all the level names, ID codes and difficulty ratings. I just cant get past the parsing so I havent really fleshed out much after that yet. There are a few tooltips and msgboxes I added just so I could see whats going on. @TheXman you can hit ESC to exit the script and PAUSE to pause/unpause it expandcollapse popup#include <MsgBoxConstants.au3> #include <File.au3> #include <StaticConstants.au3> #include <InetConstants.au3> #include <WinAPIFiles.au3> #include <FileConstants.au3> local $currentpage = 1 local $url = "https://www.smwcentral.net/?p=section&s=smwhacks&u=0&n=" & $currentpage & "&o=date&d=desc" local $readline = 1 local $classcounter = 1 local $hackname = "" local $hackdemo = "" local $hackfeatured = "" local $hackexitcount = "" local $hackdifficulty = "" local $hackauthor = "" local $hackrating = "" local $hackfilesize = "" local $hackdownloadlink = "" local $hackID = "" local $readedit = "" local $maxpages = 21 local $totallines = 1 Local $tempfile = _WinAPI_GetTempFileName(@TempDir) local $read = FileReadLine( $tempfile, $readline) local $readtext = $read local $hFileOpen local $ttmessage = "" Global $fPaused = False HotKeySet("{PAUSE}", "TogglePause") HotKeySet("{ESC}", "Terminate") Func TT() ToolTip($ttmessage, 54, 622) EndFunc Func TogglePause() $fPaused = Not $fPaused While $fPaused $ttmessage = "Script is paused." TT() Sleep(500) WEnd $ttmessage = "Script is running." TT() EndFunc ;==>TogglePause Func Terminate() Beep(300, 500) FileDelete($tempfile) sleep(300) Exit EndFunc ;==>Terminate func download();downloads one page at a time FileClose($tempfile) $url = "https://www.smwcentral.net/?p=section&s=smwhacks&u=0&n=" & $currentpage & "&o=date&d=desc" ;Local $tempfile = _WinAPI_GetTempFileName(@TempDir) Local $tempfile = _TempFile(@TempDir,"",".txt") Local $hDownload = InetGet($url, $tempfile, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND) Do $ttmessage = "downloading " & $url tt() Sleep(250) Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE) InetClose($hDownload) sleep(100) $totallines = _FileCountLines($tempfile) $ttmessage = _FileCountLines($tempfile) & " total lines" tt() sleep(500) Local $read = FileReadLine(FileOpen($tempfile), $readline) If $hFileOpen = -1 Then FileDelete($tempfile) exit EndIf $ttmessage = $hFileOpen tt() sleep(1000) MsgBox(0,"",$tempfile & @CRLF & $hFileOpen) ;Run ( "notepad.exe " & $tempfile, @WindowsDir, @SW_MAXIMIZE ) EndFunc Func parse() while 1 $read = FileReadLine($hFileOpen, $readline) $readtext = $read MsgBox(1,"",$read) $ttmessage = "parsing " & $readline & @CRLF & $readtext & @CRLF & $readedit tt() while 1 $ttmessage = "parsing2 " & $readline & @CRLF & $readtext & @CRLF & $readedit tt() $read = FileReadLine($hFileOpen, $readline) $readtext = $read MsgBox(1,"",$read) if Stringinstr($readtext, 'd=desc">Download</a>') = 1 Then;finds chunk of hacks ExitLoop Else $readline = $readline + 1 if $readline > $totallines Then $readline = 1 EndIf ContinueLoop EndIf WEnd if Stringinstr($readtext, '<td class="cell') = 1 Then;finds hack cells $readline = $readline + 1;skips to next line where data is $read = FileReadLine( $tempfile, $readline);grabs data if $classcounter = 1 Then;name $ttmessage = "parsing name" & $url tt() parsename() EndIf if $classcounter = 2 Then;demo $ttmessage = "parsing demo" & $url tt() parsedemo() EndIf if $classcounter = 3 Then;featured $ttmessage = "parsing featured" & $url tt() parsefeatured() EndIf if $classcounter = 4 Then;exit count $ttmessage = "parsing exit count" & $url tt() parseexitcount() EndIf if $classcounter = 5 then;difficulty $ttmessage = "parsing difficulty" & $url tt() parsedifficulty() EndIf if $classcounter = 6 then;author $ttmessage = "parsing author" & $url tt() parseauthor() EndIf if $classcounter = 7 then;rating $ttmessage = "parsing rating" & $url tt() parserating() EndIf if $classcounter = 8 then;file size $ttmessage = "parsing file size" & $url tt() parsefilesize() EndIf if $classcounter = 9 then;download link $ttmessage = "parsing download link" & $url tt() parsedownloadlink() $classcounter = 1 EndIf $classcounter = $classcounter + 1 EndIf if Stringinstr($readtext, 'downloads</span>') = 1 Then;finds last hack cell $classcounter = 1 EndIf if Stringinstr($readtext, '</html>') = 1 Then;finds last line in html page $readline = 1 if $currentpage < $maxpages Then Else $currentpage = $currentpage + 1 EndIf ExitLoop Else if $readline > $totallines Then $readline = 1 EndIf $readline = $readline + 1 ContinueLoop EndIf WEnd EndFunc func record() $ttmessage = "recording " & $url tt() if FileExists(@DesktopDir & "record.txt") then FileWriteLine($hackID," | " & $hackname & " | " & $hackdifficulty & " | " & $hackrating & " | " & $hackexitcount & " | " & $hackauthor) Else FileWrite($hackID," | " & $hackname & " | " & $hackdifficulty & " | " & $hackrating & " | " & $hackexitcount & " | " & $hackauthor) EndIf EndFunc Func parsename() ;********grabbing hack ID***** $readedit = $readtext While 1 if StringInStr($readedit,'"') Then;from right to left $readedit = StringTrimRight($readedit,1) ContinueLoop Else ExitLoop EndIf WEnd While 1 if StringInStr($readedit,'=') Then;from left to right $readedit = StringTrimLeft($readedit,1) ContinueLoop Else ExitLoop EndIf WEnd if StringLen($readedit) = 5 Then $hackID = $readedit EndIf ;****end hack ID**** ;****grabbing level name**** $readedit = $readtext While 1 if StringInStr($readedit,'<') Then;from right to left $readedit = StringTrimRight($readedit,1) ContinueLoop Else ExitLoop EndIf WEnd While 1 if StringInStr($readedit,'<') Then;from left to right $readedit = StringTrimLeft($readedit,1) ContinueLoop Else ExitLoop EndIf WEnd $hackname = $readedit ;****end level name**** EndFunc func parsedemo() $readedit = $readtext $readedit = StringReplace($readedit,@TAB,"") $readedit = StringReplace($readedit,"</td>","") $hackdemo = $readedit EndFunc func parsefeatured() $readedit = $readtext $readedit = StringReplace($readedit,@TAB,"") $readedit = StringReplace($readedit,"</td>","") $hackfeatured = $readedit EndFunc func parseexitcount() $hackexitcount = StringRegExp($readtext, '\d+') EndFunc func parsedifficulty() $readedit = $readtext $readedit = StringReplace($readedit,@TAB,"") $readedit = StringReplace($readedit,"</td>","") $hackdifficulty = $readedit EndFunc func parseauthor() $readedit = $readtext While 1 if StringInStr($readedit,'<') Then;from right to left $readedit = StringTrimRight($readedit,1) ContinueLoop Else ExitLoop EndIf WEnd While 1 if StringInStr($readedit,'<') Then;from left to right $readedit = StringTrimLeft($readedit,1) ContinueLoop Else ExitLoop EndIf WEnd $hackauthor = $readedit EndFunc func parserating() $readedit = $readtext $readedit = StringReplace($readedit,@TAB,"") $readedit = StringReplace($readedit,"</td>","") $hackrating = $readedit EndFunc func parsefilesize() $readedit = $readtext $readedit = StringReplace($readedit,@TAB,"") $readedit = StringReplace($readedit,"</td>","") $hackfilesize = $readedit EndFunc func parsedownloadlink() sleep(25) EndFunc While 1 download() parse() record() if $currentpage < $maxpages Then Else ExitLoop EndIf WEnd Edited August 5, 2018 by Cormin
TheXman Posted August 5, 2018 Posted August 5, 2018 I appreciate your honesty. However, I don't want to run afoul of the forum rules in case this is deemed to be game-related automation. I will wait until a moderator has weighed in before continuing to assist. Sorry. CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
Cormin Posted August 5, 2018 Author Posted August 5, 2018 @TheXmanthats fair I suppose. For the uninitiated, this doesn't affect gameplay at all. This is for a super nintendo game which clearly isn't multiplayer and cannot interact with a computer in any way
careca Posted August 5, 2018 Posted August 5, 2018 But does it interact with a game at all? Reveal hidden contents Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe
Developers Jos Posted August 5, 2018 Developers Posted August 5, 2018 On 8/5/2018 at 5:18 PM, Cormin said: This is for a super nintendo game which clearly isn't multiplayer and cannot interact with a computer in any way Expand ... and what do the forum rules say about this? Is there any differentiation about multiplayer games? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Cormin Posted August 5, 2018 Author Posted August 5, 2018 @careca no, all this does is gather level names, ID codes, authors and difficulty then store it in a database
Cormin Posted August 5, 2018 Author Posted August 5, 2018 (edited) @Jos I can take it down if you deem it necessary... look at the $hack**** variables, and the record function. All I'm trying to do is gather a list of levels and info about each one then put it in a text file. I guess its gathering info about a game but It doesnt touch anything in a game itself. Edited August 5, 2018 by Cormin
Developers Jos Posted August 5, 2018 Developers Posted August 5, 2018 Looks like we had an short encounter just over a year ago and this feels like you are exploring boundaries. Let's not do this as the rules are clear! Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Moderators JLogan3o13 Posted August 5, 2018 Moderators Posted August 5, 2018 You obviously knew there would be an issue, as you state yourself in your post above that you didn't want to post the whole script. I agree with Jos, this is you pushing boundaries again. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Recommended Posts