2009-12-09 02:08:12 +01:00
|
|
|
#!/usr/bin/perl -w -I /home/msmud/lib/lib/perl5/site_perl/5.10.0/
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2017-03-05 22:33:31 +01:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2007-05-20 22:44:44 +02:00
|
|
|
# quick and dirty by :pragma
|
|
|
|
|
|
|
|
use LWP::Simple;
|
|
|
|
|
|
|
|
my ($defint, $phrase, $text, $entry, $entries, $i);
|
|
|
|
|
|
|
|
if ($#ARGV < 0)
|
|
|
|
{
|
|
|
|
print "What phrase would you like to define?\n";
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
|
|
|
$phrase = join("%20", @ARGV);
|
|
|
|
|
|
|
|
$entry = 1;
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($phrase =~ m/([0-9]+)%20(.*)/)
|
2007-05-20 22:44:44 +02:00
|
|
|
{
|
|
|
|
$entry = $1;
|
|
|
|
$phrase = $2;
|
|
|
|
}
|
|
|
|
|
2010-03-22 08:33:44 +01:00
|
|
|
$text = get("http://dictionary.reference.com/browse/$phrase");
|
2007-05-20 22:44:44 +02:00
|
|
|
|
|
|
|
$phrase =~ s/\%20/ /g;
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($text =~ m/no dictionary results/i)
|
2007-05-20 22:44:44 +02:00
|
|
|
{
|
|
|
|
print "No entry found for '$phrase'. ";
|
|
|
|
|
2019-06-26 18:34:19 +02:00
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($text =~ m/Did you mean <a class.*?>(.*?)<\/a>/g)
|
2007-05-20 22:44:44 +02:00
|
|
|
{
|
2010-03-22 08:33:44 +01:00
|
|
|
print "Did you mean '$1'? Alternate suggestions: ";
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2009-12-09 02:08:12 +01:00
|
|
|
$i = 90;
|
2010-03-22 08:33:44 +01:00
|
|
|
$comma = "";
|
2019-05-28 18:19:42 +02:00
|
|
|
while ($text =~ m/<div id="spellSuggestWrapper"><li .*?><a href=.*?>(.*?)<\/a>/g && $i > 0)
|
2007-05-20 22:44:44 +02:00
|
|
|
{
|
2010-03-22 08:33:44 +01:00
|
|
|
print "$comma$1";
|
2007-05-20 22:44:44 +02:00
|
|
|
$i--;
|
2010-03-22 08:33:44 +01:00
|
|
|
$comma = ", ";
|
2007-05-20 22:44:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
# if ($text =~ m/Encyclopedia suggestions:/g)
|
2007-05-20 22:44:44 +02:00
|
|
|
# {
|
|
|
|
# print "Suggestions: ";
|
|
|
|
#
|
|
|
|
# $i = 30;
|
2019-06-26 18:34:19 +02:00
|
|
|
# while ($text =~ m/<a href=".*?\/search\?r=13&q=.*?>(.*?)<\/a>/g
|
2007-05-20 22:44:44 +02:00
|
|
|
# && $i > 0)
|
|
|
|
# {
|
|
|
|
# print "$1, ";
|
|
|
|
# $i--;
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
|
|
|
|
print "\n";
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($text =~ m/- (.*?) dictionary result/g)
|
2007-05-20 22:44:44 +02:00
|
|
|
{
|
|
|
|
$entries = $1;
|
|
|
|
}
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
$entries = 1 if (not defined $entries);
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($entry > $entries)
|
2007-05-20 22:44:44 +02:00
|
|
|
{
|
2009-12-09 02:08:12 +01:00
|
|
|
print "No entry found for $phrase.\n";
|
2007-05-20 22:44:44 +02:00
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
2009-12-09 02:08:12 +01:00
|
|
|
print "$phrase: ";
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2009-12-09 02:08:12 +01:00
|
|
|
$i = $entry;
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2009-12-09 02:08:12 +01:00
|
|
|
$defint = "";
|
|
|
|
|
|
|
|
my $quote = chr(226) . chr(128) . chr(156);
|
|
|
|
my $quote2 = chr(226) . chr(128) . chr(157);
|
|
|
|
my $dash = chr(226) . chr(128) . chr(147);
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
while ($i <= $entries)
|
2007-05-20 22:44:44 +02:00
|
|
|
{
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($text =~ m/<td>(.*?)<\/td>/gs)
|
2007-05-20 22:44:44 +02:00
|
|
|
{
|
|
|
|
$defint = $1;
|
|
|
|
}
|
|
|
|
|
2009-12-09 02:08:12 +01:00
|
|
|
# and now for some fugly beautifying regexps...
|
|
|
|
|
|
|
|
$defint =~ s/$quote/"/g;
|
|
|
|
$defint =~ s/$quote2/"/g;
|
|
|
|
$defint =~ s/$dash/-/g;
|
|
|
|
$defint =~ s/<b>Pronun.*?<BR>//gsi;
|
|
|
|
$defint =~ s/<.*?>//gsi;
|
|
|
|
$defint =~ s/\ \;/ /gi;
|
|
|
|
$defint =~ s/\&.*?\;//g;
|
|
|
|
$defint =~ s/\r\n//gs;
|
|
|
|
$defint =~ s/\( P \)//gs;
|
|
|
|
$defint =~ s/\s+/ /gs;
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($defint =~ /interfaceflash/) {
|
2009-12-09 02:08:12 +01:00
|
|
|
$i++;
|
|
|
|
next;
|
|
|
|
}
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2009-12-09 02:08:12 +01:00
|
|
|
$i++ and next if $defint eq " ";
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2009-12-09 02:08:12 +01:00
|
|
|
print "$i) $defint ";
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2009-12-09 02:08:12 +01:00
|
|
|
$i++;
|
|
|
|
}
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2009-12-09 02:08:12 +01:00
|
|
|
print "\n";
|