package Plagger::Plugin::CustomFeed::Yahoo360JP; use strict; use base qw( Plagger::Plugin ); use DateTime::Format::Strptime; use Encode; use Time::HiRes; use Plagger::Mechanize; sub plugin_id { my $self = shift; $self->class_id . '-' . $self->conf->{username}; } sub register { my($self, $context) = @_; $context->register_hook( $self, 'subscription.load' => \&load, ); } sub load { my($self, $context) = @_; my $feed = Plagger::Feed->new; $feed->aggregator(sub { $self->aggregate(@_) }); $context->subscription->add($feed); } sub aggregate { my($self, $context, $args) = @_; my $start = "http://360.yahoo.co.jp/"; my $mech = Plagger::Mechanize->new(cookie_jar => $self->cookie_jar); $mech->get($start); if ($mech->content =~ /mgb_login/) { my $success; eval { $success = $self->login($mech) }; if ($@ && $@ =~ /persistent/) { $context->log(error => "Login failed. Clear cookie and redo."); $mech->cookie_jar->clear; $mech->get($start); sleep 3; eval { $success = $self->login($mech) }; } return unless $success; } $context->log(info => "Login to Yahoo! succeeded."); my $feed = Plagger::Feed->new; $feed->type('yahoo360jp'); $feed->title('Yahoo! 360'); $feed->link('http://360.yahoo.co.jp/friends/content.html'); my $blast_feed; if ($self->conf->{fetch_blast}) { $blast_feed = Plagger::Feed->new; $blast_feed->type('yahoo360jp-blast'); $blast_feed->title('Yahoo! 360 ひとこと'); $blast_feed->link('http://360.yahoo.co.jp/'); } # get friends blogs $mech->get("http://360.yahoo.co.jp/friends/content.html"); # preserve link to blast page here ... used later my $link = $mech->find_link( url_regex => qr/form_submitted=friends_content_head/ ); my $re = decode('utf-8', <<'RE');
RE my $now = Plagger::Date->now; my $format = DateTime::Format::Strptime->new(pattern => decode('utf-8', '%Y %m月%d日 %H:%M')); my $content = decode('utf-8', $mech->content); while ($content =~ /$re/g) { my $args = { profile => $1, nickname => $2, icon => $3, height => $4, width => $5, link => $6, title => $7, date => $8, month => $9, }; if ($self->conf->{fetch_body}) { my $item = $self->cache->get_callback( "item-$args->{link}", sub { $self->fetch_body($mech, $args->{link}) }, "1 hour", ); $args->{body} = $item->{body} if $item->{body}; } $self->add_entry($feed, $args, $now, $format); } $re = decode('utf-8', <<'RE');