Sunday, 18 March 2012

Hourly timestamp in your twitter stream

This is such a silly project that I'm only going to post the code here as a curio. I have uploaded the code here in order to keep all it in one place ;-).

I liked the idea of an hourly time code in my twitter stream so started following @big_ben_clock which helpfully BONGs on the hour. This is OK if you are in the same time zone as Big Ben and can quickly enumerate the BONGS at, say, 9 O'Clock but useless otherwise.

I thought it would be worth a couple of minutes of my time to convert the tweet text to a localtime time of the tweets generated by @big_ben_clock making the 'service' more universal and get rid of the BONGS - which wear thin after a while.

UPDATE
@RealIvanSanchez has pointed out that there's an account @coucou_suisse that performs a similar service. So, take your pick.

Here's the code for the TTYtter extension: (needs Date::Manip)

#bigben2localtime
use Date::Manip;

# Simply follow @big_ben_clock or @coucou_suisse and this will replace the tweet with a
# localtime conversion of the tweet timestamp.
# @pr4wn

sub bb_time_convert {
  my $date = shift;
  my $s;

  $s = substr( $date, 8, 5 ); # hh:mm
  return( $s );

}

$handle = sub {


my $ref = shift;

my $ESC = pack("C", 27);
my $BOLDON = ($ansi) ? "${ESC}[1;31m" : '';
my $BOLDOFF = ($ansi) ? "${ESC}[0m" : '';

if ($ref->{user}->{screen_name} eq 'big_ben_clock' ||
$ref->{user}->{screen_name} eq 'coucou_suisse' ) {
   
  my $created_at = ParseDate($ref->{'created_at'});
  $ref->{text} = $BOLDON . bb_time_convert($created_at) . $BOLDOFF;

}

&defaulthandle ( $ref );

}

Here's both accounts showing the same localtime despite being in different time zones.

1 comment:

fletcher cook said...

Your tips are remarkable. I regularly read your blog and its very helpful.
Headshop