Command Line Twitter

Created: April 26, 2011 · Last modified: March 1, 2012

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?).\
";
         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.\
");
        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!\
";
      }else{
         print "Something went wrong, not added. Error code: ";
         print "$content\
";
      }
      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.


Comments

Brad

BTW, my .ttytterrc, if you're curious. I don't use the @stormdragon2976 mod of my extension, though; my original looks for 'user:pass' in ~/.instapaper (I've sanitized a couple of things in the file below). I also run ttytter in screen, but I'm sure you've already set that up.

$ cat .ttytterrc
# Geting around OAuth ratelimit issues temporarily
#authtype=basic
#user=augmentedfourth:badpass

# Old SSL workaround
#url https://twitter.com/statuses/home_timeline.json
# New easy SSL method
ssl=1

# Old mentions workaround
#track=augmentedfourth @augmentedfourth
# New easy mentions method
mentions=1

# Wait 5sec before posting
slowpost=5

# Use color
ansi=1

# Keep trying if timeout on login
hold=1

# Render newlines in tweets
newline=1

# Version check on startup
vcheck=1

# Wrap at word breaks, at 90 character lines
wrap=90

# Don't show tweets that match this regex
filter=/Now listening to/

# Disable direct message checking (these go to my phone)
dmpause=0

# Add my modified extension for '/later' to put a tweet in Instapaper
exts=/home/bbeyenhof/bin/instapaper.pl

# Turn on readline support and tab-complete the following names
readline=@a @bunch @of @people

Categories