leuce Posted May 14, 2007 Share Posted May 14, 2007 G'day everyone I've written a script that visits the Wikipedia and extracts some information from it (basically, it creates a bilingual word list). The startfile is a list of words. The endfile is a bilingual list of words. Here it is: expandcollapse popup; #include <File.au3> $startup = MsgBox (4, "Wikterma 1.1", "Welcome to Wikterma 1.0" & @CRLF & "by Samuel Murray, 2007" & @CRLF & @CRLF & "This program creates a bilingual word list" & @CRLF & "based on interwiki links on the Wikipedia." & @CRLF & @CRLF & "Have you read the readme.txt file?", "") If $startup = 7 Then Exit $startfilename = InputBox ("Name of unilingual word list", "Enter the full name of your initial unilingual word list") $startfile = FileOpen($startfilename, 0) $lines = _FileCountLines ($startfilename) $endfilename = InputBox ("Name of bilingual word list", "Enter a name for your final bilingual word list") $endfile = FileOpen($endfilename, 1) $language = InputBox ("Target language name", "Enter the target language's name in that language (default is Dutch)", "Nederlands") $langcode = InputBox ("Target language code", "Enter the target language's language code in lower case (default is Dutch)", "nl") $sleeptime = InputBox ("(Optional) Sleep time between fetches", "Enter the time in milliseconds that Wikterma should allow for fetching a web page (default is 2 seconds)", "2000") $traytip = MsgBox (4, "(Optional) See progress?", "Do you want to see the progress as a traytip?") For $i = 1 to $lines $targetword1 = "(empty)" $sourceword = FileReadLine($startfilename, $i) $wikipage = InetGet("http://en.wikipedia.org/wiki/" & $sourceword, "temp.txt") $targetword0 = StringRegExp(FileRead(FileOpen('temp.txt', 0)), '(?<=' & $langcode & '\.wikipedia\.org/wiki/).*(?=">' & $language & ')', 1) If IsArray($targetword0) Then $targetword1 = $targetword0[0] If IsArray($targetword0) Then FileWriteLine($endfile, $sourceword & " :: " & $targetword1) If $traytip = 6 Then TrayTip ("Wikterma now parsing...", "Term " & $i & " of " & $lines & ". " & $sourceword & " :: " & $targetword1, 10) Sleep ($sleeptime) FileClose ('temp.txt') Next MsgBox (0, "Done!", "All done!", 10) After varying numbers of cycles (sometimes 40, sometimes 100) the script stops with the error message that the maximum number of files are open. AFAIK I do close the file inside the loop. What else can I do? What else can be wrong? Thanks Samuel Link to comment Share on other sites More sharing options...
Xenobiologist Posted May 14, 2007 Share Posted May 14, 2007 Hi, haven't lookes closer, but I would use _FileReadToArray instead of of FileReadLine ... So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Developers Jos Posted May 14, 2007 Developers Share Posted May 14, 2007 You cannot close a Filename but need to close the fileHandle as returned by fileopen: For $i = 1 To $lines $targetword1 = "(empty)" $sourceword = FileReadLine($startfilename, $i) $wikipage = InetGet("http://en.wikipedia.org/wiki/" & $sourceword, "temp.txt") $H_TF = FileOpen('temp.txt', 0) $targetword0 = StringRegExp(FileRead($H_TF), '(?<=' & $langcode & '\.wikipedia\.org/wiki/).*(?=">' & $language & ')', 1) If IsArray($targetword0) Then $targetword1 = $targetword0[0] If IsArray($targetword0) Then FileWriteLine($endfile, $sourceword & " :: " & $targetword1) If $traytip = 6 Then TrayTip("Wikterma now parsing...", "Term " & $i & " of " & $lines & ". " & $sourceword & " :: " & $targetword1, 10) Sleep($sleeptime) FileClose($H_TF) Next 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. Link to comment Share on other sites More sharing options...
leuce Posted May 15, 2007 Author Share Posted May 15, 2007 You cannot close a Filename but need to close the fileHandle as returned by fileopen.Thanks, JdeB!Now I just have to figure out why the script doesn't write to the file in real time (it creates an empty file and then only at the end of the script it writes all the stuff to that file). It is as if the script keeps everything in memory and doesn't really write it to the file.Thanks again. Link to comment Share on other sites More sharing options...
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