From c6a78a196987fd7a0200cc9c3d9b79bd84152a5b Mon Sep 17 00:00:00 2001 From: Ralf Ertzinger Date: Tue, 29 Jul 2008 09:12:48 +0200 Subject: [PATCH] - Add qdb.us support --- quotesite/QdbGrabber.pm | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 quotesite/QdbGrabber.pm 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; -- 1.8.3.1