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);
14 use HTML::Entities qw(decode_entities);
21 my $self = $class->SUPER::new();
23 $self->{'NAME'} = 'twitter.com';
24 $self->{'PATTERNS'} = ['(http://twitter.com/(?:\#\!/)?[^/]+/status(?:es)?/(\d+))'];
27 $self->_prepare_parameters();
38 my $p = XML::Simple->new();
44 $metadata->{'URL'} = $url;
45 $metadata->{'ID'} = $2;
46 $metadata->{'TYPE'} = 'quote';
47 $metadata->{'SOURCE'} = $self->{'NAME'};
48 $metadata->{'CONTENT'} = undef;
50 # Get the XML file containing the quote
51 unless(defined($content = LWP::Simple::get(sprintf('http://api.twitter.com/1/statuses/show/%s.xml', $2)))) {
52 $self->error('Could not download quote');
56 unless(defined($t = $p->XMLin($content))) {
57 $self->error('Could not parse XML metadata');
61 $metadata->{'CONTENT'} = encode("utf8", decode_entities(decode("utf8", $t->{'text'})));
62 $metadata->{'ID'} = $t->{'user'}->{'screen_name'} . '/' . $metadata->{'ID'};
64 unless(defined($metadata->{'CONTENT'})) {
65 $self->error('Could not extract quote content');