root/trunk/plagger/lib/Plagger/Plugin/Filter/HatenaBookmarkTag.pm

Revision 1492 (checked in by miyagawa, 14 years ago)

Refactored XML::Feed and Aggregator::Simple to split out the parser and discover functionality to a separate module: Plagger::FeedParser?, and new methods to UserAgent?: $ua->find_parse($url) and $ua->fetch_parse($url). Fixes #381

  • Property svn:keywords set to Id Revision
Line 
1 package Plagger::Plugin::Filter::HatenaBookmarkTag;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use Plagger::UserAgent;
6 use URI;
7
8 sub register {
9     my($self, $context) = @_;
10     $context->register_hook(
11         $self,
12         'update.entry.fixup' => \&update,
13     );
14 }
15
16 sub update {
17     my($self, $context, $args) = @_;
18
19     # xxx need cache & interval
20     my $agent = Plagger::UserAgent->new;
21     my $url  = 'http://b.hatena.ne.jp/entry/rss/' . $args->{entry}->permalink;
22     my $feed = eval { $agent->fetch_parse( URI->new($url) ) };
23
24     if ($@) {
25         $context->log(error => "Feed error $url: $@");
26         return;
27     }
28
29     for my $entry ($feed->entries) {
30         my $tag = $entry->category or next;
31            $tag = [ $tag ] unless ref($tag);
32
33         for my $t (@{$tag}) {
34             $args->{entry}->add_tag($t);
35         }
36     }
37 }
38
39 1;
40
41 __END__
42
43 =head1 NAME
44
45 Plagger::Plugin::Filter::HatenaBookmarkTag - Fetch tags from Hatena Bookmark
46
47 =head1 SYNOPSIS
48
49   - module: Filter::HatenaBookmarkTag
50
51 =head1 DESCRIPTION
52
53 B<Note: this module is mostly untested and written just for a proof of
54 concept. If you run this on your box with real feeds, Hatena might
55 throttle your IP. See http://b.hatena.ne.jp/ for details.>
56
57 This plugin queries Hatena Bookmark (L<http://b.hatena.ne.jp/>) using
58 its RSS feeds API to get the tags people added to the entries.
59
60 =head1 AUTHOR
61
62 Tatsuhiko Miyagawa
63
64 =head1 SEE ALSO
65
66 L<Plagger>, L<Plagger::Plugin::Filter::HatenaBookmarkUsersCount>,
67 L<http://b.hatena.ne.jp/>
68
69 =cut
Note: See TracBrowser for help on using the browser.