Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.

2016/09/09

Net::Twitter Cookbook: Tweetstorm!

I had planned to get into following, lists and blocking, but a wild hair came over me and I decided I wanted to make a tweetstorm app.

What's a tweetstorm?


And this is the inner loop of it.
  1. my @tweetstorm_text ; # previously generated. URL shortening and numbering are assumed  
  2. my $screen_name ; #your screen name as text  
  3. my $status_id ; #created but not set, so first tweet won't be a reply-to  
  4.   
  5. for my $status ( @tweetstorm_text } ) {  
  6.   
  7.     my $tweet ; # the object containing the twee  
  8.     $tweet->{status} = $status ;  
  9.     $tweet->{in_reply_to_status_id} = $status_id if $status_id ;  
  10.   
  11.     if ( $twit->update($tweet) ) { #if Tweet is successful  
  12.   
  13.         # we get your profile, which contains your most recent tweet  
  14.         # $status_id gets set to the ID of that tweet, which then  
  15.         # gets used for the next tweet.  
  16.   
  17.         my $profiles  
  18.             = $twit->lookup_users( { screen_name => $config->{user} } ) ;  
  19.         my $profile = shift @$profiles ;  
  20.         my $prev    = $profile->{status} ;  
  21.         $status_id = $profile->{status}->{id} ;  
  22.         }  
  23.     }  

So, that's it. I've thrown the whole thing on GitHub if you want to play with it yourself.

No comments:

Post a Comment