otsune's SnakeOil RSSフィード

python -c "print''.join([chr(x) for x in 111&1101,110+~-~11,10^11*11,110+~-~11,-~101,-~11^11*11,~-110,111&11*11,11+11+10,11|~-0110,1-~11^11*11,10^11*11,-~11^11*11,110,101])"

2007-04-22

Publish::Twitterにウェイトをいれてみた

| Publish::Twitterにウェイトをいれてみた - otsune's SnakeOil  を含むブックマーク はてなブックマーク - Publish::Twitterにウェイトをいれてみた - otsune's SnakeOil  Publish::Twitterにウェイトをいれてみた - otsune's SnakeOil  のブックマークコメント

=== 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.