2020-02-01 23:30:32 +01:00
|
|
|
#!/usr/bin/perl -w
|
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/.
|
2019-06-26 18:34:19 +02:00
|
|
|
|
2009-12-09 02:08:12 +01:00
|
|
|
# quick and dirty by :pragma
|
2019-06-26 18:34:19 +02:00
|
|
|
|
2009-12-09 02:08:12 +01:00
|
|
|
use strict;
|
|
|
|
use LWP::UserAgent;
|
2019-06-26 18:34:19 +02:00
|
|
|
|
2009-12-09 02:08:12 +01:00
|
|
|
my ($defint, $phrase, $text, $entry, $entries, $i);
|
|
|
|
my @defs;
|
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
if ($#ARGV < 0) {
|
|
|
|
print "What phrase would you like to define?\n";
|
|
|
|
die;
|
2009-12-09 02:08:12 +01:00
|
|
|
}
|
2019-06-26 18:34:19 +02:00
|
|
|
|
2009-12-09 02:08:12 +01:00
|
|
|
$phrase = join("+", @ARGV);
|
2019-06-26 18:34:19 +02:00
|
|
|
|
2009-12-09 02:08:12 +01:00
|
|
|
$entry = 1;
|
2019-06-26 18:34:19 +02:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
if ($phrase =~ m/([0-9]+)\+(.*)/) {
|
|
|
|
$entry = $1;
|
|
|
|
$phrase = $2;
|
2009-12-09 02:08:12 +01:00
|
|
|
}
|
2019-06-26 18:34:19 +02:00
|
|
|
|
2009-12-09 02:08:12 +01:00
|
|
|
my $ua = LWP::UserAgent->new;
|
|
|
|
$ua->agent("howdy");
|
|
|
|
my $response = $ua->get("http://www.google.com/search?q=define:$phrase");
|
|
|
|
$phrase =~ s/\+/ /g;
|
2019-06-26 18:34:19 +02:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
if (not $response->is_success) { exit(1); }
|
2019-06-26 18:34:19 +02:00
|
|
|
|
2009-12-09 02:08:12 +01:00
|
|
|
$text = $response->content;
|
2020-02-15 23:38:32 +01:00
|
|
|
if ($text =~ m/No definitions were found/i) {
|
|
|
|
print "No entry found for '$phrase'. ";
|
|
|
|
print "\n";
|
|
|
|
exit 1;
|
2009-12-09 02:08:12 +01:00
|
|
|
}
|
2019-06-26 18:34:19 +02:00
|
|
|
|
2009-12-09 02:08:12 +01:00
|
|
|
print "$phrase: ";
|
2019-06-26 18:34:19 +02:00
|
|
|
|
2009-12-09 02:08:12 +01:00
|
|
|
$i = $entry;
|
2019-06-26 18:34:19 +02:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
while ($i <= $entry + 5) {
|
|
|
|
if ($text =~ m/<li>(.*?)<br>/gs) { push @defs, $1; }
|
|
|
|
$i++;
|
2009-12-09 02:08:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
my %uniq = map { $_ => 1 } @defs;
|
|
|
|
@defs = keys %uniq;
|
|
|
|
|
|
|
|
my $comma = "";
|
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
for ($i = 1; $i <= $#defs + 1; $i++) {
|
2009-12-09 02:08:12 +01:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
# and now for some fugly beautifying regexps...
|
2009-12-09 02:08:12 +01:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
my $quote = chr(226) . chr(128) . chr(156);
|
|
|
|
my $quote2 = chr(226) . chr(128) . chr(157);
|
|
|
|
my $dash = chr(226) . chr(128) . chr(147);
|
2009-12-09 02:08:12 +01:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
$_ = $defs[$i - 1];
|
2009-12-09 02:08:12 +01:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
s/$quote/"/g;
|
|
|
|
s/$quote2/"/g;
|
|
|
|
s/$dash/-/g;
|
|
|
|
s/<b>Pronun.*?<BR>//gsi;
|
|
|
|
s/<.*?>//gsi;
|
|
|
|
s/\ \;/ /gi;
|
|
|
|
s/\&.*?\;//g;
|
|
|
|
s/\r\n//gs;
|
|
|
|
s/\( P \)//gs;
|
|
|
|
s/\s+/ /gs;
|
2009-12-09 02:08:12 +01:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
print "$i) $_$comma";
|
|
|
|
$comma = ", ";
|
2009-12-09 02:08:12 +01:00
|
|
|
}
|