Thursday, 26 April 2012

Your last tweets as mail .sig

Just a quick note. I was enjoying a bit of banter with some TTYtter users (Spanish division) the other day, when the subject of using cowsay with tweets came up. This led on to suggestions of updating one's mail sig with one's latest tweet.

So, here's my take on it using my pwntter database. It does little more that look for my last tweet that is not a reply (starting with @) or an RT (starting with RT) and writing a to a .sig file.

#!/bin/sh

SIGDIR=$HOME/.sig
SIGFILE=$SIGDIR/tweet.sig

if [ ! -e $SIGDIR ]; then

  mkdir -p $SIGDIR

fi

TWEET=`mysql -u pwntter -ppwntter -B -h localhost pwntter << EOF
  SELECT DATE_FORMAT(created_at, '%d-%m-%Y at %H:%i') AS cdate, text
  FROM tweets
  WHERE screen_name = 'pr4wn' AND text NOT RLIKE '^@|^RT\b'
  ORDER BY id DESC LIMIT 1
EOF`

echo -e "\nLast tweet by me [@pr4wn] on ${TWEET:11:19}\n" | tee $SIGFILE
cowsay -w -W 50 ${TWEET:31} | tee -a $SIGFILE



Sample output


Last tweet by me [@pr4wn] on 26-04-2012 at 07:47

 __________________________________________________
/ BLOG: TTYtter related again. Writing your latest \
| pearls of wisdom on twitter to a .sig file.      |
\ http://t.co/VuUvQ1SO                             /
 --------------------------------------------------
        \   ^__^
         \  (OO)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Simply run in crontab as frequently as you think sensible.

Saturday, 21 April 2012

Suppressing DMs you have already read

I don't use direct messages often, so every time I fire up TTYtter, the same DMs appear in my timeline when it performs its "-- checking for most recent direct messages:" function.

It's not a huge issue, but I had a few minutes spare to write an extension to suppress them.

Download the extension here and read the TTYtter documentation on how to run extensions.

Note, the first time you use the extension, it will display the most recent DMs as it will not have stored the ids of them! 

$store->{last_dm_id} = 0; 
$store->{dmbookmark} = "$ENV{'HOME'}/.ttytter.dmbookmark";

if( open( DM, $store->{dmbookmark} ) ) {
 $store->{last_dm_id} = scalar( );
 close( DM ); 
}

$dmhandle = sub {

  my $ref = shift;

  if ( $ref->{id} > $store->{last_dm_id} ) {

    $store->{last_dm_id} = $ref->{id};
    &defaultdmhandle( $ref );

 }

};

$dmconclude = sub {

 if(open(DM, ">".$store->{dmbookmark})) {

   print DM $store->{last_dm_id};
   close( DM ); } 

  else { 
    print $stdout "Failed to write: $!\n"; 

  } 

  &defaultdmconclude; 

};