2007-04-22
Publish::Twitterにウェイトをいれてみた
plagger |
![]()
=== assets/plugins/Publish-Twitter/twitter.tt ================================================================== --- assets/plugins/Publish-Twitter/twitter.tt (revision 1851) +++ assets/plugins/Publish-Twitter/twitter.tt (local) @@ -0,0 +1 @@ +[% IF entry.body %][% entry.body_text %][% ELSE %][% entry.title_text %][% END %] [% entry.permalink %]
=== lib/Plagger/Plugin/Publish/Twitter.pm ================================================================== --- lib/Plagger/Plugin/Publish/Twitter.pm (revision 1851) +++ lib/Plagger/Plugin/Publish/Twitter.pm (local) @@ -4,6 +4,7 @@ use Encode; use Net::Twitter; +use Time::HiRes qw(sleep); sub register { my($self, $context) = @_; @@ -29,13 +30,17 @@ sub publish_entry { my($self, $context, $args) = @_; - my $body = ( $args->{entry}->summary->plaintext || $args->{entry}->title ) . " " . $args->{entry}->permalink; + my $body = $self->templatize('twitter.tt', $args); # TODO: FIX when Summary configurable. if ( length($body) > 159 ) { $body = substr($body, 0, 159); } $context->log(info => "Updating Twitter status to '$body'"); $self->{twitter}->update( encode_utf8($body) ) or $context->error("Can't update twitter status"); + + my $sleeping_time = $self->conf->{interval} || 15; + $context->log(info => "sleep $sleeping_time."); + sleep( $sleeping_time ); } 1; @@ -68,6 +73,10 @@ Twitter password. Required. +=item interval + +Optional. + =item apiurl OPTIONAL. The URL of the API for twitter.com. This defaults to "http://twitter.com/statuses" if not set.
コメント
トラックバック - http://subtech.g.hatena.ne.jp/otsune/20070422
