perl 5 まとめウィキ

やっぱり時代はAnyEventですよね。
Feedが更新されたらon_fetchで指定したcode referenceが実行されます。
といっても、単なるpollingなのでほどほどにね!

#!/usr/bin/env perl
use AnyEvent;
use AnyEvent::Feed;
 
my $FLICKR_IDOLS_RSS
    = 'http://pipes.yahoo.com/pipes/pipe.run?_id=WtqVti0j3BGz37dMJxOy0Q&_render=rss&search=idol+japanese+sexy';
my $POLLING_INTERVAL = 30;
 
run();
exit;
 
sub run {
    my $done = AnyEvent->condvar;
 
    my $feed_reader = AnyEvent::Feed->new(
        url => $FLICKR_IDOLS_RSS,
        interval => $POLLING_INTERVAL,
 
        on_fetch => \&on_fetch,
        on_error => \&on_error,
        on_eof => \&on_eof,
    );
 
    $done->recv;
}
 
sub on_fetch {
    my ( $feed_reader, $new_entries, $feed, $error ) = @_;
 
    if ( defined $error ) {
        warn "ERROR: $error\n";
        return;
    }
 
    for my $entry_container (@$new_entries) {
        my $hash = $entry_container->[0];
        my $entry = $entry_container->[1]->{entry};
        warn $entry->{link};
        warn $entry->{description};
    }
}
 
sub on_error {
    my $error = shift;
    warn "ERROR: $error";
    $done->send;
}
 
sub on_eof {
    $done->send;
}

このページへのコメント

9unYc1 Appreciate you sharing, great article.Really looking forward to read more. Want more.

0
Posted by check this out 2013年12月20日(金) 07:54:51 返信

コメントをかく


「http://」を含む投稿は禁止されています。

利用規約をご確認のうえご記入下さい

Wiki内検索

Menu

ここは自由に編集できるエリアです。

フリーエリア

どなたでも編集できます