Greytree

TamWiki

For a mouse who is a packrat

Main » wp.pl irssi script
show a summary of a wikipedia entry to the current channel

Summary:this is what goes at the top of the site

Up: ^Irssi^

Wikipedia is a great source of information on the web. This script grabs a summary of a wikipedia page and presents the result back to the channel the bot was activated from.

The script uses a functionality that a lot of people don't know about: someone has created a small database of wikipedia summaries that are requested and returned via a DNS query.

Since we're in Perl, there's a nifty Perl implementation as well:

"Getting wikipedia summaries via DNS in Perl"
  1. use Net::DNS;
  2. my $res = Net::DNS::Resolver->new;
  3.  
  4. sub wikipedia {
  5.   my($name) = @_;
  6.   my $q = $res->query("$name.wp.dg.cx", "TXT");
  7.   if($q) {
  8.     for my $rr($q->answer) {
  9.       next unless $rr->type eq "TXT";
  10.       return join "", $rr->char_str_list;
  11.     }
  12.   }
  13. }

The script responds to a message in a channel or a query containing:

 !wp <WIKIPEDIA PAGE>

And presents the information back to the channel or query as an action.

The script can be found here: http://public.tamaratemple.com/irssi/wp.pl.txt


Tags: Categories: ComputerStuff

Recent Changes | Printable View | Page History | Edit Page
Page last modified on October 08, 2011, at 04:58 PM by tamara