Debian Codegraph @

bin/wikipedia

raw
1 #!/usr/bin/perl
2
3 =head1 NAME
4
5 wikipedia - lookup an entry in the wikipedia
6
7 =head1 SYNOPSIS
8
9 % wikipedia [-l lang] perl
10
11 =head1 DESCRIPTION
12
13 wikipedia is a command line tool for looking up a topic in the wikipedia
14 and printing it to STDOUT. Useful if you spend a lot of time in a shell
15 and don't want to fire up a web browser to see what something is.
16
17 =head1 AUTHORS
18
19 =over 4
20
21 =item * Slaven Rezic <[email protected]>
22
23 =back
24
25 =cut
26
27 use strict;
28 use WWW::Wikipedia;
29 use Text::Autoformat;
30 use Pod::Usage;
31 use Getopt::Std;
32
33 my %options;
34 getopts( 'l:', \%options );
35
36 my $term = shift;
37 pod2usage( { verbose => 1 } ) if !defined( $term );
38
39 my $wiki = WWW::Wikipedia->new( language => $options{ l } || 'en' );
40 my $entry = $wiki->search( $term );
41
42 ## use a pager if we can
43 eval( 'use IO::Page' );
44 if ( $entry ) {
45 my $text = $entry->text();
46 if ( $text ) { print $text; }
47 else {
48 print "Specific entry not found, see also:\n";
49 foreach ( $entry->related() ) { print " - $_\n"; }
50 }
51 }
52 else { print qq("$term" not found in wikipedia\n) }
53