Changeset 1343

Show
Ignore:
Timestamp:
08/16/06 22:29:29
Author:
taro
Message:

add variable interval time
add config for scraping big numbers

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/Plugin/Filter/Delicious.pm

    r189 r1343  
    1919 
    2020    # xxx need cache & interval 
    21     sleep 1; 
    22     my $url  = 'http://del.icio.us/rss/url/' . md5_hex($args->{entry}->permalink); 
     21    my $interval = $self->conf->{interval} || 1; 
     22    sleep $interval; 
     23 
     24    my $md5  = md5_hex($args->{entry}->permalink); 
     25    my $url  = "http://del.icio.us/rss/url/$md5"; 
    2326    my $feed = XML::Feed->parse( URI->new($url) ); 
    2427 
     
    3740    } 
    3841 
    39     $args->{entry}->meta->{delicious_users} = $feed->entries; 
     42    my $delicious_users = $feed->entries; 
     43    if ($delicious_users >= 30 && $self->conf->{scrape_big_numbers}) { 
     44        sleep $interval; 
     45 
     46        my $url = "http://del.icio.us/url/$md5"; 
     47        my $ua  = Plagger::UserAgent->new; 
     48        my $res = $ua->fetch($url); 
     49 
     50        if ($res->is_error) { 
     51            $context->log(warn => "Fetch error $url: " . $res->http_response->message); 
     52            return; 
     53        } 
     54 
     55        $delicious_users = 
     56            ( $res->content =~ m#<h4[^>]*>[^<>]*this url has been saved by\D+(\d+)#s )[0]; 
     57    } 
     58    $args->{entry}->meta->{delicious_users} = $delicious_users; 
    4059} 
    4160