| 1 |
package Plagger::Plugin::Filter::Delicious; |
|---|
| 2 |
use strict; |
|---|
| 3 |
use base qw( Plagger::Plugin ); |
|---|
| 4 |
|
|---|
| 5 |
use Digest::MD5 qw(md5_hex); |
|---|
| 6 |
use URI; |
|---|
| 7 |
use XML::Feed; |
|---|
| 8 |
|
|---|
| 9 |
sub register { |
|---|
| 10 |
my($self, $context) = @_; |
|---|
| 11 |
$context->register_hook( |
|---|
| 12 |
$self, |
|---|
| 13 |
'update.entry.fixup' => \&update, |
|---|
| 14 |
); |
|---|
| 15 |
} |
|---|
| 16 |
|
|---|
| 17 |
sub update { |
|---|
| 18 |
my($self, $context, $args) = @_; |
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
sleep 1; |
|---|
| 22 |
my $url = 'http://del.icio.us/rss/url/' . md5_hex($args->{entry}->permalink); |
|---|
| 23 |
my $feed = XML::Feed->parse( URI->new($url) ); |
|---|
| 24 |
|
|---|
| 25 |
unless ($feed) { |
|---|
| 26 |
$context->log(warn => "Feed error $url: " . XML::Feed->errstr); |
|---|
| 27 |
return; |
|---|
| 28 |
} |
|---|
| 29 |
|
|---|
| 30 |
for my $entry ($feed->entries) { |
|---|
| 31 |
my @tag = split / /, ($entry->category || ''); |
|---|
| 32 |
@tag or next; |
|---|
| 33 |
|
|---|
| 34 |
for my $tag (@tag) { |
|---|
| 35 |
$args->{entry}->add_tag($tag); |
|---|
| 36 |
} |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
$args->{entry}->meta->{delicious_users} = $feed->entries; |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
1; |
|---|
| 43 |
|
|---|
| 44 |
__END__ |
|---|
| 45 |
|
|---|
| 46 |
=head1 NAME |
|---|
| 47 |
|
|---|
| 48 |
Plagger::Plugin::Filter::Delicious - Fetch tags and users count from del.icio.us |
|---|
| 49 |
|
|---|
| 50 |
=head1 SYNOPSIS |
|---|
| 51 |
|
|---|
| 52 |
- module: Filter::Delicious |
|---|
| 53 |
|
|---|
| 54 |
=head1 DESCRIPTION |
|---|
| 55 |
|
|---|
| 56 |
B<Note: this module is mostly untested and written just for a proof of |
|---|
| 57 |
concept. If you run this on your box with real feeds, del.icio.us wlil |
|---|
| 58 |
be likely to ban your IP. See http://del.icio.us/help/ for details.> |
|---|
| 59 |
|
|---|
| 60 |
This plugin queries del.icio.us using its RSS feeds API to get the |
|---|
| 61 |
tags people added to the entries, and how many people bookmarked them. |
|---|
| 62 |
|
|---|
| 63 |
Users count is stored in C<delicious_users> metadata of |
|---|
| 64 |
Plagger::Entry, so that other plugins and smartfeeds can make use of. |
|---|
| 65 |
|
|---|
| 66 |
=head1 AUTHOR |
|---|
| 67 |
|
|---|
| 68 |
Tatsuhiko Miyagawa |
|---|
| 69 |
|
|---|
| 70 |
=head1 SEE ALSO |
|---|
| 71 |
|
|---|
| 72 |
L<Plagger>, L<http://del.icio.us/help/> |
|---|
| 73 |
|
|---|
| 74 |
=cut |
|---|