1 # (c) 2010 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
6 package TwitterGrabber;
9 @ISA = qw(GrabberBase);
11 use LWP::Simple qw(!get);
20 my $self = $class->SUPER::new();
22 $self->{'NAME'} = 'twitter.com';
23 $self->{'PATTERNS'} = ['(http://twitter.com/(?:\#\!/)?[^/]+/status/(\d+))'];
26 $self->_prepare_parameters();
37 my $p = XML::Simple->new();
43 $metadata->{'URL'} = $url;
44 $metadata->{'ID'} = $2;
45 $metadata->{'TYPE'} = 'quote';
46 $metadata->{'SOURCE'} = $self->{'NAME'};
47 $metadata->{'CONTENT'} = undef;
49 # Get the XML file containing the quote
50 unless(defined($content = LWP::Simple::get(sprintf('http://api.twitter.com/1/statuses/show/%s.xml', $2)))) {
51 $self->error('Could not download quote');
55 unless(defined($t = $p->XMLin($content))) {
56 $self->error('Could not parse XML metadata');
60 $metadata->{'CONTENT'} = $t->{'text'};
61 $metadata->{'ID'} = $t->{'user'}->{'screen_name'} . '/' . $metadata->{'ID'};
63 unless(defined($metadata->{'CONTENT'})) {
64 $self->error('Could not extract quote content');