From: Ralf Ertzinger Date: Sun, 7 Dec 2008 22:55:24 +0000 (+0100) Subject: Merge branch 'master' of ssh://sun@ryoko:22003/home/sun/GIT/quotesite X-Git-Url: https://git.camperquake.de/gitweb.cgi?p=quotesite.git;a=commitdiff_plain;h=20af9b1c4f051c0830ba35b8d3d15439c499e119;hp=efd2a46770962a8ecf55e18c819b7c52042456d4 Merge branch 'master' of ssh://sun@ryoko:22003/home/sun/GIT/quotesite --- diff --git a/quotesite.pl b/quotesite.pl index cfbc3aa..a6414a9 100644 --- a/quotesite.pl +++ b/quotesite.pl @@ -4,7 +4,7 @@ # licensed under GNU GPL v2 use strict; -use Irssi 20020324 qw (command_bind command_runsub signal_add_first signal_add_last); +use Irssi 20020324 qw (command_bind command_runsub signal_add_first signal_add_last window_find_refnum); use vars qw($VERSION %IRSSI); use XML::Simple; use Data::Dumper; @@ -43,7 +43,7 @@ sub write_irssi { $text[0] = 'quotesite: ' . $text[0]; - if (defined $witem) { + if (defined($witem) && ref($witem)) { $witem->print(sprintf(shift(@text), @text), MSGLEVEL_CLIENTCRAP); } else { Irssi::print(sprintf(shift(@text), @text)); @@ -83,7 +83,9 @@ sub check_for_link { # Offer the message to all Grabbers in turn foreach $g (@grabbers) { + # $g->pushio(sub{ write_irssi($witem, @_); }); ($m, $p) = $g->get($message); + # $g->popio(); while (defined($m)) { write_irssi($witem, '%%R>>> %%Y%s%%N %%G%s', $m->{'SOURCE'}, $m->{'ID'}); @@ -346,13 +348,13 @@ sub cmdhandler { foreach (@grabbers) { $_->setdebug(1); } - write_irssi(undef, 'Enabled debugging'); + write_irssi($item, 'Enabled debugging'); } elsif ($params[0] eq 'nodebug') { $debug = 0; foreach (@grabbers) { $_->setdebug(0); } - write_irssi(undef, 'Disabled debugging'); + write_irssi($item, 'Disabled debugging'); } } diff --git a/quotesite/Base.pm b/quotesite/Base.pm index f0fa439..08897c9 100644 --- a/quotesite/Base.pm +++ b/quotesite/Base.pm @@ -8,7 +8,7 @@ use Data::Dumper; sub new { my $class = shift; - my $self = {'_DEBUG' => 0, '_OUT' => sub {print shift}}; + my $self = {'_DEBUG' => 0, '_OUT' => sub {print shift}, '_OUTSTACK' => []}; bless($self, $class); @@ -91,6 +91,23 @@ sub setio { $self->{'_OUT'} = $io; } +sub pushio { + my $self = shift; + my $io = shift; + + push(@{$self->{'_OUTSTACK'}}, $self->{'_OUT'}); + $self->setio($io); +} + +sub popio { + my $self = shift; + my $io = pop(@{$self->{'_OUTSTACK'}}); + + if (defined($io)) { + $self->setio($io); + } +} + sub getconfstr { my $self = shift; my $s = 'Options for ' . $self->{'NAME'} . ":\n"; diff --git a/quotesite/GermanBashGrabber.pm b/quotesite/GermanBashGrabber.pm index 3fb4e63..8b52db9 100644 --- a/quotesite/GermanBashGrabber.pm +++ b/quotesite/GermanBashGrabber.pm @@ -19,7 +19,8 @@ sub new { my $self = $class->SUPER::new(); $self->{'NAME'} = 'germanbash'; - $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*german-bash\.org/(\d+))']; + $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*german-bash\.org/(\d+))', + '(http://(?:[-a-zA-Z0-9_.]+\.)*german-bash\.org/action/show/id/(\d+))']; bless($self, $class); $self->_prepare_parameters(); diff --git a/quotesite/QdbGrabber.pm b/quotesite/QdbGrabber.pm new file mode 100644 index 0000000..0a65255 --- /dev/null +++ b/quotesite/QdbGrabber.pm @@ -0,0 +1,74 @@ +# (c) 2007 by Ralf Ertzinger +# licensed under GNU GPL v2 +# +# Grabber for qdb.us + +package QdbGrabber; + +use GrabberBase; +@ISA = qw(GrabberBase); + +use LWP::Simple qw(!get); +use HTML::TokeParser; +use Data::Dumper; + +use strict; + +sub new { + my $class = shift; + my $self = $class->SUPER::new(); + + $self->{'NAME'} = 'qdb.us'; + $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*qdb\.us/(\d+))']; + + bless($self, $class); + $self->_prepare_parameters(); + + return $self; +} + +sub _parse { + my $self = shift; + my $url = shift; + my $pattern = shift; + my $content; + my $metadata = {}; + my $p; + my $t; + my $t2; + + $url =~ m|$pattern|; + $url = $1; + + $metadata->{'URL'} = $url; + $metadata->{'ID'} = $2; + $metadata->{'TYPE'} = 'quote'; + $metadata->{'SOURCE'} = $self->{'NAME'}; + $metadata->{'CONTENT'} = undef; + + # Get the HTML file containing the quote + unless(defined($content = LWP::Simple::get(sprintf('http://qdb.us/?%s', $2)))) { + $self->error('Could not download quote'); + return undef; + } + + $p = HTML::TokeParser->new(\$content); + + OUTER: while ($t = $p->get_tag('table')) { + if (exists($t->[1]->{'class'}) && ($t->[1]->{'class'} eq 'quote')) { + while ($t2 = $p->get_tag('p')) { + $metadata->{'CONTENT'} = $p->get_text('/p'); + last OUTER; + } + } + } + + unless(defined($metadata->{'CONTENT'})) { + $self->error('Could not extract quote content'); + return undef; + } + + return $metadata; +} + +1; diff --git a/quotesite/iBashGrabber.pm b/quotesite/iBashGrabber.pm new file mode 100644 index 0000000..04bd07d --- /dev/null +++ b/quotesite/iBashGrabber.pm @@ -0,0 +1,72 @@ +# (c) 2007 by Ralf Ertzinger +# licensed under GNU GPL v2 +# +# Grabber for german-bash.org + +package iBashGrabber; + +use GrabberBase; +@ISA = qw(GrabberBase); + +use LWP::Simple qw(!get); +use HTML::TokeParser; +use Data::Dumper; +use Encode; + +use strict; + +sub new { + my $class = shift; + my $self = $class->SUPER::new(); + + $self->{'NAME'} = 'ibash.de'; + $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*ibash.de/zitat_(\d+)\.html)']; + + bless($self, $class); + $self->_prepare_parameters(); + + return $self; +} + +sub _parse { + my $self = shift; + my $url = shift; + my $pattern = shift; + my $content; + my $metadata = {}; + my $p; + my $t; + + $url =~ m|$pattern|; + $url = $1; + + $metadata->{'URL'} = $url; + $metadata->{'ID'} = $2; + $metadata->{'TYPE'} = 'quote'; + $metadata->{'SOURCE'} = $self->{'NAME'}; + $metadata->{'CONTENT'} = undef; + + # Get the HTML file containing the quote + unless(defined($content = LWP::Simple::get(sprintf('http://www.ibash.de/zitat_%s.html', $2)))) { + $self->error('Could not download quote'); + return undef; + } + + $p = HTML::TokeParser->new(\$content); + + while ($t = $p->get_tag('td')) { + if (exists($t->[1]->{'class'}) && ($t->[1]->{'class'} eq 'quote')) { + $metadata->{'CONTENT'} = $p->get_text('/td'); + Encode::from_to($metadata->{'CONTENT'}, 'iso-8859-1', 'utf8'); + } + } + + unless(defined($metadata->{'CONTENT'})) { + $self->error('Could not extract quote content'); + return undef; + } + + return $metadata; +} + +1;