TTYtter group support library

2009.06.26

As referenced in my previous post I’m a pretty big fan of TTYtter.  I won’t go into it’s advantages here you can find that information in my previous post.  I follow quite a few people so one of the first things I did when I started using TTYtter was to write a group add on library for it.  The previous post and the TTYtter site have good information on how to enable these libraries and also how to write them.  This library is pretty good size and performs quite a few operations that I thought would be a good example for someone else looking to extend TTYtter for their own use.

Operations:

  1. Custom commands for handling groups
  2. Bookmark of tweet id for place tracking what already was evaluated
  3. Filtering based on dynamic lists of users
  4. Add users to groups from inside TTYtter
  5. Remove users from groups inside TTYtter
  6. Add users to multiple groups

The easiest way to get started is to install this and get it going.  Download the library from svn and modify the one configuration item at the top of the library to set the group file storage path.  Reference the library from your .ttytterc file or use the library command line switch.

Once loaded you might want to have a look at the command set supported out of the library, there is built in help accessible from within TTYtter

/grouphelp
Group commands are as follows.

/group [groupname]
display stored tweets from group

/groups
list the current groups on the filesystem

/grouplist [groupname]
list the members of group [groupname]

/groupadd [groupname] [username]
add [username] to group [groupname]

/groupdel [groupname] [username]
delete [username] from group [groupname]

At this point you can add some users to a group via something like the following command which adds myself to a group called coders.

TTYtter> /groupadd coders vkoser
User vkoser added to group coders
TTYtter>

Once you have some groups built up it’s really easy to view them in TTYtter by using the /group coders command to list the last 20 tweets from that group.  That’s reasonable if your activly using TTYtter but it’s much more useful to use something like GNU Screen to view multiple groups and assign one screen section per group.  I typically set mine up with split windows and a large scrollback buffer configuration which lets me scroll back through pages of information.

I hope someone can get some value out of this as a learning tool and possibly expand it for your own use.  It’s not overly error proof as an add on for my own use but it works pretty well.  If anyone would like to submit changes or enhancements to the library just send them over to me or contact me on twitter and I’ll see about getting them migrated into the library.

The current release can be gotten here [TTYtterGroups.pl] from the svn repository.

Categories : tips  tools
Tags :     

extending TTYtter

2009.06.15

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.

Categories : tips  tools
Tags :