Warning: include_once(/home/kosertech/kosertech.com/wp-content/plugins/wordpress-support/wordpress-support.php): failed to open stream: Permission denied in /home/kosertech/kosertech.com/wp-settings.php on line 207

Warning: include_once(): Failed opening '/home/kosertech/kosertech.com/wp-content/plugins/wordpress-support/wordpress-support.php' for inclusion (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear') in /home/kosertech/kosertech.com/wp-settings.php on line 207
kosertech » extending TTYtter
15
Jun
2009

extending TTYtter

One of my favorite twitter apps is @TTYtter and you can download it from floodgap.com.  It’s written by Cameron Kaiser aka @doctorlinguist on twitter.  Now before we get all crazy and discount TTYtter because it’s not a fancy graphical application with sliding panels and lots of things you can click you need to understand why this is a great tool.

  • Scriptable (make your own search/harvesting tool)
  • Schedulable (run it, grab search output dump to a file etc…)
  • Automate posting information (use it to tweet your coffee pot status etc…)
  • Extensible
  • Open Source
  • Easily runs on almost all varieties of Unix

There are many other features but if your prone to requiring a mouse to interact with a computer this might not be a good fit for you.  It’s the idea of extensibility that I’m going to discuss in this post.  TTYtter has a really nice way to extend it’s functionality or override it’s default behaviors.  One of the things I like most is the ability to just change how it behaves.  If your using an open source client you could just modify the source but then your stuck with what to do when there is an upgrade you have to integrate your changes into the new version if they weren’t something that was accepted back into the project distribution.  TTYtter uses a user defined library that is loaded from your own file.  You can specify a library at runtime that will be loaded with TTYtter that gives a user the opportunity through the use of a little perl to extend or alter the default behaviors.  The big win for this architecture is if a new version of TTYtter comes out it still just loads your custom user library and you get all your customizations with the new version.

I’ve recently fallen back in love with iChat on the mac after finding a nice plug-in that allowed a unified contacts list and I’ve grown used to the time stamp format.  I wanted to add this time stamp format into TTYtter.  There is a default provided time stamp option on TTYtter but it places the time stamp on each tweet which really adds to the width of the displayed line.  I had the idea to create a time stamp that inserted itself every 5 minutes or so that would give me an indication of 5 minute blocks of tweets and also let me find my place if I’m away from my desktop for a meeting or something so I can scroll back to unread items.

Picture 9

You can see in the above screen shot there are two displayed timestamps in the form of “–Mon Jun..”.  The small library I’m going to discuss here inserts those time stamps into the listing of tweets.  This probably isn’t the most elegant way to handle this but it does give you a preview of the type of alterations you can do to TTYtter with your own libraries.

Lets take a look at the code:

$handle = sub {

my $delayInSeconds = 60 * 5;

#load the Lib_past with current time on first run
if(!$Lib_firstrun){
     $Lib_firstrun = true;
     print "Seeding timestamp generator\n";
     $Lib_past = time;
}

#if we have elapsed $delayInSeconds then print a time stamp
if($Lib_past < (time - ($delayInSeconds))){
     $Lib_past = time;
     print "--" . localtime time . "\n\n";
     print "\n";
}

#this allows TTYtter to handle displaying the tweet normally
my $ref = shift;
&defaulthandle($ref);

return 1;

};

The above code is fairly self explanitory but lets take a look at whats happening.  You want to save this code into a file, ichat.pl for instance might be a nice logical choice.  Then when launching TTYtter you need to specify -lib=ichat.pl and this will load your library along with TTYtter.  The above code will be called every time a tweet is received allowing you to customize and extend what happens at that time during code execution.  The last two lines of code are of interest because those two lines allow TTYtter to handle the tweet display as it normally would.  If you want to modify how the tweet is displayed you have full access to do so and override the default behavior.  This is useful for modifying how details are shown, for instance you could add the source client information if you like.  For this library we just want to display our custom time stamp so we’ll let TTYtter handle the tweet display.

You can read all about this advanced use of TTYtter at the website where it is documented.  I encourage you to play around with it it really is quite fun to get things working just the way you like.  I have a much more complicated library that allows me to group users and filter those users tweets into files.  It also allows for group management within TTYtter via custom /commands.  I’ll post details on that in the coming days and add it to the software download page.

Comments are closed.