Changeset 1945

Show
Ignore:
Timestamp:
05/01/07 00:00:02
Author:
otsune
Message:

Change from RSS scrape to JSON.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/deps/Filter-Delicious.yaml

    r1362 r1945  
    22author: Tatsuhiko Miyagawa, Taro Funaki 
    33depends: 
     4  JSON::Syck: 0 
  • trunk/plagger/lib/Plagger/Plugin/Filter/Delicious.pm

    r1734 r1945  
    33use base qw( Plagger::Plugin ); 
    44 
     5use JSON::Syck; 
    56use Digest::MD5 qw(md5_hex); 
    67use Plagger::UserAgent; 
    7 use XML::Feed; 
    88 
    99sub register { 
     
    2222 
    2323    my $md5  = md5_hex($args->{entry}->permalink); 
    24     my $url = "http://del.icio.us/rss/url/$md5"; 
     24    my $url = "http://badges.del.icio.us/feeds/json/url/data?hash=$md5"; 
    2525 
    2626    $self->log(info => "Going to fetch $url"); 
     
    3333        return; 
    3434    } 
    35  
    36     my $feed = XML::Feed->parse(\$res->content); 
    37  
    38     unless ($feed) { 
    39         $context->log(warn => "Feed error $url: " . XML::Feed->errstr); 
     35     
     36    my $data = JSON::Syck::Load($res->content); 
     37    unless (ref $data eq 'ARRAY') { 
     38        $self->log(error => "json parse error: $data"); 
    4039        return; 
    4140    } 
     41    my $h = @{$data}[0]; 
    4242 
    43     for my $entry ($feed->entries) { 
    44         my @tag = split / /, ($entry->category || ''); 
    45            @tag or next; 
    46  
    47         for my $tag (@tag) { 
    48             $args->{entry}->add_tag($tag); 
    49         } 
     43    for my $tag (keys %{$h->{top_tags}}) { 
     44        $args->{entry}->add_tag($tag); 
     45        $self->log(debug => "add tag $tag"); 
    5046    } 
    5147 
    52     my $delicious_users = $feed->entries; 
    53     if ($delicious_users >= 30 && $self->conf->{scrape_big_numbers}) { 
    54         my $url = "http://del.icio.us/url/$md5"; 
    55         $self->log(info => "users count is more than 30. Trying to scrape from $url."); 
    56         sleep $interval; 
    57  
    58         my $res = $ua->fetch($url); 
    59  
    60         if ($res->is_error) { 
    61             $context->log(warn => "Fetch error $url: " . $res->http_response->message); 
    62             return; 
    63         } 
    64  
    65         $delicious_users = 
    66             ( $res->content =~ m#<h4[^>]*>[^<>]*this url has been saved by\D+(\d+)#s )[0]; 
    67     } 
     48    my $delicious_users = $h->{total_posts} || 0; 
    6849    $args->{entry}->meta->{delicious_rate} = rate_of_color($delicious_users); 
    6950    $args->{entry}->meta->{delicious_users} = $delicious_users; 
     
    9576be likely to ban your IP. See http://del.icio.us/help/ for details.> 
    9677 
    97 This plugin queries del.icio.us using its RSS feeds API to get the 
    98 tags people added to the entries, and how many people bookmarked them. 
     78This plugin queries del.icio.us using its JSON API to get the tags 
     79people added to the entries, and how many people bookmarked them. 
    9980 
    10081Users count is stored in C<delicious_users> metadata of 
     
    10788=head1 SEE ALSO 
    10889 
    109 L<Plagger>, L<http://del.icio.us/help/> 
     90L<Plagger>, L<http://del.icio.us/help/>, L<http://del.icio.us/help/json/url> 
    11091 
    11192=cut