diff options
author | lookshe <lookshe@fumuga.com> | 2012-03-07 19:48:54 +0100 |
---|---|---|
committer | lookshe <lookshe@fumuga.com> | 2012-03-07 19:48:54 +0100 |
commit | 4814f77744953001de6ccfd023f788eb3d5e4cf6 (patch) | |
tree | 70ce4c2c8e3cd359e30136e790cddfe4a4024cbf | |
parent | f55dfe54e1920d9eb9ca09e6519557cade22636b (diff) |
some more fixes...
-rw-r--r-- | wiki2.pl | 26 |
1 files changed, 21 insertions, 5 deletions
@@ -8,14 +8,30 @@ use HTML::StripTags qw(strip_tags); binmode(STDOUT, ":utf8"); +my $query = $ARGV[0]; my $lang = $ARGV[1]; if (!$lang) { $lang = "de"; } +my $found = 0; +my $result; -my $wiki = WWW::Wikipedia->new( language => $lang); - -my $result = $wiki->search( "$ARGV[0]" ); +while ($found < 5) { + $found++; + my $wiki = WWW::Wikipedia->new( language => $lang); + $result = $wiki->search( "$query" ); + if (defined $result) { + my @tmplines = split('\n', $result->text_basic()); + if ($#tmplines == 0 && $tmplines[0] =~ m/^#/) { + $query = $tmplines[0]; + $query =~ s/^#\w*\s(.*)$/$1/; + } else { + break; + } + } else { + break; + } +} if (defined $result) { my @lines = split('\n', $result->text_basic()); my @newlines; @@ -86,8 +102,8 @@ if (defined $result) { } } if ($isDis && $lst) { - print "For more see http://$lang.wikipedia.org/wiki/$ARGV[0]\n"; + print "For more see http://$lang.wikipedia.org/wiki/$query\n"; } } else { - print "No matches with $ARGV[0]\n"; + print "No matches with $query\n"; } |