2019-12-15 22:41:50 +01:00
|
|
|
#!/usr/bin/perl
|
2009-12-09 02:08:12 +01: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/.
|
|
|
|
|
2009-12-09 02:08:12 +01:00
|
|
|
use strict;
|
|
|
|
use WWW::Wikipedia;
|
2019-05-28 18:19:42 +02:00
|
|
|
use HTML::Parse;
|
|
|
|
use HTML::FormatText;
|
2009-12-09 02:08:12 +01:00
|
|
|
|
|
|
|
my $term = join(' ', @ARGV);
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if (not $term) {
|
2009-12-09 02:08:12 +01:00
|
|
|
print "Usage: !wikipedia <term>\n";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
my $wiki = WWW::Wikipedia->new(language => 'en');
|
|
|
|
my $entry = $wiki->search($term);
|
2009-12-09 02:08:12 +01:00
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($entry) {
|
2009-12-09 02:08:12 +01:00
|
|
|
my $text = $entry->text();
|
2019-06-26 18:34:19 +02:00
|
|
|
|
|
|
|
if ($text) {
|
2019-12-15 22:41:50 +01:00
|
|
|
$text =~ s/\{\{.*?}}//msg;
|
2019-05-28 18:19:42 +02:00
|
|
|
$text =~ s/\[\[//g;
|
|
|
|
$text =~ s/\]\]//g;
|
|
|
|
$text =~ s/<ref>.*?<\/ref>//g;
|
|
|
|
$text =~ s/__[A-Z]+__//g;
|
|
|
|
$text =~ s/\s+\(\)//msg;
|
|
|
|
$text = HTML::FormatText->new->format(parse_html($text));
|
2019-06-26 18:34:19 +02:00
|
|
|
print $text;
|
2019-05-28 18:19:42 +02:00
|
|
|
} else {
|
2009-12-09 02:08:12 +01:00
|
|
|
print "Specific entry not found, see also: ";
|
|
|
|
my $semi = "";
|
2019-05-28 18:19:42 +02:00
|
|
|
foreach ($entry->related()) { print "$semi$_"; $semi = "; "; }
|
2009-12-09 02:08:12 +01:00
|
|
|
}
|
2019-06-26 18:34:19 +02:00
|
|
|
} else {
|
|
|
|
print qq("$term" not found in Wikipedia\n)
|
2009-12-09 02:08:12 +01:00
|
|
|
}
|
|
|
|
|