This script provides a fast way to "search" wikipedia from irssi.
Example:
prints http://de.wikipedia.org/wiki/Rolling_Stones in the current channel
and
Note: this script requires curl.
1 #!/usr/bin/perl 2 3 # This program is free software: you can redistribute it and/or modify 4 # it under the terms of the GNU General Public License as published by 5 # the Free Software Foundation, either version 3 of the License, or 6 # (at your option) any later version. 7 # 8 # This program is distributed in the hope that it will be useful, 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 # GNU General Public License for more details. 12 # 13 # You should have received a copy of the GNU General Public License 14 # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 %IRSSI = ( 17 'authors' => 'Haui', 18 'contact' => 'haui45@web.de', 19 'name' => 'wiki-search', 20 'description' => 'this script allows you to "search"' . 21 'wikipedia from irssi', 22 'license' => 'GPL', 23 'version' => '0.1' 24 ); 25 26 use strict; 27 #uncomment this, if you're sure of having curl installed 28 `which curl` or die "fatal...curl not found!"; 29 my $string = ""; 30 sub wiki { 31 # data - contains the parameters for /wiki 32 # server - the active server in window 33 # witem - the active window item (eg. channel, query) 34 # or undef if the window is empty 35 my ($data, $server, $witem) = @_; 36 37 if (!$server || !$server->{connected}) { 38 Irssi::print("Not connected to server"); 39 return; 40 } 41 42 if ($data && $witem && ($witem->{type} eq "CHANNEL" || 43 $witem->{type} eq "QUERY")) { 44 my $string = "http://de.wikipedia.org/wiki/"; 45 chop($data) while (substr($data, length($data)-1) eq " "); 46 $data =~ s/(\b)([a-z])/\1\u\2/g; 47 $data =~ s/ /_/g; 48 my $url = "$string"."$data"; 49 my @array = `curl -s \"$url\"`; 50 my $tmp = grep (/<b>Diese Seite existiert nicht<\/b>/, @array); 51 undef(@array); 52 if ($tmp != 0) 53 { 54 $url = "http://de.wikipedia.org/wiki/Spezial:Suche/" . "$data"; 55 $witem->command("/echo Nichts gefunden, versuche $url"); 56 $tmp = 0; 57 return; 58 } 59 60 $witem->command("SAY $url"); 61 # there's query/channel active in window 62 #$witem->command("MSG ".$witem->{name}." Hello!"); 63 64 } else { 65 Irssi::print("No active channel/query in window"); 66 } 67 } 68 69 sub ewiki { 70 # data - contains the parameters for /wiki 71 # server - the active server in window 72 # witem - the active window item (eg. channel, query) 73 # or undef if the window is empty 74 my ($data, $server, $witem) = @_; 75 76 if (!$server || !$server->{connected}) { 77 Irssi::print("Not connected to server"); 78 return; 79 } 80 81 if ($data && $witem && ($witem->{type} eq "CHANNEL" || 82 $witem->{type} eq "QUERY")) { 83 $string = "http://en.wikipedia.org/wiki/"; 84 chop($data) while (substr($data, length($data)-1) eq " "); 85 $data =~ s/(\b)([a-z])/\1\u\2/g; 86 $data =~ s/ /_/g; 87 my $url = "$string"."$data"; 88 my @array = `curl -s \"$url\"`; 89 my $tmp = grep (/<b>Wikipedia does not have an article with this exact name.<\/b>/, @array); 90 undef(@array); 91 if ($tmp != 0) 92 { 93 $url = "http://en.wikipedia.org/wiki/Special:Search/" . "$data"; 94 $witem->command("/ECHO Nothing found, try $url"); 95 $tmp = 0; 96 return; 97 } 98 $witem->command("SAY $url"); 99 100 } else { 101 Irssi::print("No active channel/query in window"); 102 } 103 } 104 105 106 Irssi::command_bind('wiki', 'wiki'); 107 Irssi::command_bind('ewiki', 'ewiki'); 108