Definition from Wiktionary, the free dictionary
Jump to: navigation, search

stop don't go

The first version that ran through entire wordlist without dying.[edit]

<?PHP #php script to open a word list file, check if there's an entry for it on wikitionary, and spit out a file that could be inserted into MediaWiki to facilitate adding entries for missing words

$array = file("allwords.txt"); set_time_limit(0) ; $outputfile = fopen("outputfile.txt","w"); //opens asdfcounter.txt to read $notfoundstr = "Wiktionary does not have an entry for"; $randrange1 = 250000; $randrange2 = 550000;

foreach ($array as $line_num => $line) { $line=chop($line); #echo "line=$line

#file_get_contents("". str_replace(" ", "_", $line) #str_rep to convert to wiktionary naming convention #read page into var. for loop to retry on timouts # i like that this works to as such. # getcha that url, but real gentleman-like.. $wait=0; usleep(rand($randrange1,$randrange2)); for ( $wiktionary = file_get_contents("". str_replace(" ", "_", $line) ) ; $wiktionary==FALSE; sleep($wait+=10) # not needed, pauses increasingly before next call so as not not to hammer server. ) { $z++; if ($z==100) {echo "Zee z is greater than thee. Exiting."; exit;} $wiktionary = file_get_contents("". str_replace(" ", "_", $line) ) ; echo "
Timeout on $line. Waiting $wait and retrying. Time: " . time() . "
"; flush(); ob_flush(); } #echo "
Out of loop. wiktionary=

$notfound = strpos($wiktionary, $notfoundstr);

if ($notfound) { #echo "
In not found loop. Line=$line.
"; #echo "notfoundpos: $notfound.
wiktionary;"; echo "
Wikt's missing: <A HREF=".str_replace(" ", "_", $line)."&action=edit>$line</A>
"; /*echo "FYI: <A HREF=$line>Google it</A> - <A HREF=$line></A> - <A HREF=$line></A> - <A HREF=$line></A> - <A HREF=$line></A> - <A HREF=$line></A>
"; */

fwrite($outputfile, "* $line - (FYI: Google it. - - - - -\n"); # echo "
* $line
(FYI: Google it. - - - - -
"; } #end if notfound

# keeps browser connection alive, hopefully: may not need. echo '~'; flush(); ob_flush();

#$i++; if ($i > 5) { exit; } # break loop during testing. } #end of file as array

echo "
End of file
. Program finished. Judge success for yourself.


#now i spent quite some number of hours figuring out how to do this, so be kind and please remember, the goal wasn't solely or even mostly to write a program that would produce something that could be used to facilitate filling in holes on a Wiktionary. #no, it was also to give myself cause to explore the PHP manual, and to learn some things that i didn't need to learn, and to leave the remnants of those detours somewhere where i could later visit. #so be kind, and realize that your programming critique's been thought of, and deemed unworthy of creedence,, yet. #so be kind, cuz it's fun 2b.