Diff: CommandLineTwitter
Differences between current version and previous revision of CommandLineTwitter.
Other diffs: Previous Major Revision, Previous Author
| Newer page: | version 4 | Last edited on March 1, 2012 12:19 pm | by PhilHollenback | |
| Older page: | version 3 | Last edited on March 1, 2012 12:17 pm | by PhilHollenback | Revert | 
current version
Command Line Twitter
My notes on setting up the command line twitter client ttytter on my Mac.
Install the ttytter readline module with
$ sudo cpan Term::ReadLine::TTYtter
This gives you a readline which counts total characters per line (VERY IMPORTANT).
my ~/.ttytterrc:
ansi=1 verify=1 track='#sysadmin' readline=1 vcheck=1 mentions=1 urlopen=open %U avatar=open %U backload=40 simplestart=1 ssl=1 newline=1 exts=/Users/barney/.ttytter/instapaper.pl extpref_instapaper_username=barney@example.com extpref_instapaper_password=badpass
mkdir ~/.ttytter
Put instapaper.pl in the ~/.ttytter directory:
#instapaper.pl Extension code by @augmentedfourth http://www.twitter.com/augmentedfourth
# Add a command (/later) to add tweet to Instapaper
#Released under the WTFPL: http://en.wikipedia.org/wiki/WTFPL
$addaction = sub {
   my $command = shift;
   if ($command =~ m#^/later (.+)#) {
      my $tweet_id=$1;
      my $tweet = &get_tweet($tweet_id);
      if (!$tweet->{'id_str'}) {
         print $stdout "-- sorry, no such tweet (yet?).\n";
         return 1;
      }
      #modified to use .ttytterrc by @stormdragon2976 http://www.twitter.com/stormdragon2976
      if ((!defined($extpref_instapaper_username)) || (!defined($extpref_instapaper_password)))
      {
        print $streamout ("Instapaper information not found. ");
        print $streamout ("Please add extpref_instapaper_username and extpref_instapaper_password ");
        print $streamout ("to your .ttytterrc.\n");
        return 1;
      }
      my $ip_user = $extpref_instapaper_username;
      my $ip_pass = $extpref_instapaper_password;
      my $add_url="twitter.com/$tweet->{'user'}->{'screen_name'}/statuses/$tweet->{'id'}";
      my $ip_url="https://www.instapaper.com/api/add?url=" . $add_url . "&username=" .
        $ip_user . "&password=" . $ip_pass . "&auto-title=1";
      my $content = `curl -s \"$ip_url\"`;
      if ($content =~ /201/){
         print "Added to Instapaper!\n";
      }else{
         print "Something went wrong, not added. Error code: ";
         print "$content\n";
      }
      return 1;
   }
   return 0;
};
To Do
I really want to rewrite the instapaper extension as an exercise to make it all perl (and try using LWP::Simple). It would also be nice if the extension printed a 'trying to add to instapaper ... success!' sort of message instead of just waiting until success or failure to complete (although the asynchronous nature of ttytter may make that difficult).
I also really want to see if I can write an extension to use the bit.ly api to shorten urls instead of using is.gd.
Another fun idea: an extension that creates github gists from tweets or something along those lines.

