Mar 31 2008

My TweetSpeak Update

Published by Robert Fischer at 12:13 pm under Uncategorized

For those of you who are on Twitter, you might appreciate TweetSpeak. It makes Twitter a bit more like office banter by speaking it in the background. Here are some updates I made to it — basically, I added some error handling to deal with having too many client requests, put a few more substitutions in so that Alex figured out how to translate Twitterese like “kthxbye” and “crrrrrraaaaaaaaaaaaaaaxzy”, and generally cleaned up Twitterisms in the feed.


This code is released under the GPL 2, and is based on the original by Ward Cunningham.

#!/usr/bin/perl
# Copyright (c) 2008, Cunningham & Cunningham, Inc
# Enhanced by Smokejumper Consulting
# Released under GPL v2.

my $user = 'YourUser:urp@ssw0rd';
my $db = $ENV{'HOME'} . '/.tweet-db';
my $current;
$current = `cat $db` if -e $db;

print "Using database at $db\n";
while (1) {
  twitt();
  `echo $current > $db`;
  sleep(180) if $user;
}

sub twitt() {

  #`say -v Victoria tweet tweet?`;

  my $xml = $user
    ? `curl -s -u $user http://twitter.com/statuses/friends_timeline.xml`
    : `curl -s http://twitter.com/statuses/public_timeline.xml`;

  if($xml =~ m|(.+)<\/error>|) {
    print "ERROR: $1\n";
    my $msg = "Error reading from Twitter.";
    $msg = $1 if $1 =~ m|^(.*?\.)|;
    `say -v Victoria $msg`;
    sleep(120) if $user;
    return;
  }

  for (reverse(split(//, $xml))) {

    my $id = $1 if /(.*?)<\/id>/;
    next if $current and $id <= $current;
    $current = $id;
    next if /&#\d{3,6};/;

    my $name = $1 if /(.*?)<\/name>/;
    $name =~ s/Ross/Ross Mayfield/;
    $name =~ s/RobertFischer/Robert Fischer/;
    $name =~ s/danah/Danah Boyd/;
    $name =~ s/marshallk/Marshall Kirkpatrick/;
    $name =~ s/(Jeff Atwood)/$1 of CodingHorror/;
    $name =~ s/Chr15 P1r1LL0/Chris Pirillo/;

    my $text = $1 if /(.*?)<\/text>/;
    $text =~ s|\s*&\s*| and |g;
    $text =~ s|\s*<\s*| less than |g;
    $text =~ s|\s*>\s*| greater than |g;
    $text =~ s|"|"|g;
    print "$id $name -- $text\n";
    next if $text =~ /\b(el|que|muy)\b/;

    $text =~ s/'/'"'"'/g;
    $text =~ s/\bw\// with /g;
    $text =~ s/&#\d+;/ blah /g;
    $text =~ s/:?\s*http:\/\/\S+/ at this url /g;
    $text =~ s/\b@(\w+)/$1.  /;
    $text =~ s/\b:D\b//g;
    $text =~ s/\b:P\b//g;
    $text =~ s/\b:-p\b//g;
    $text =~ s/\b:P\b//g;
    $text =~ s/\bLOL\b/ ha ha. /g;
    $text =~ s/\bFTW/for the win/ig;
    $text =~ s/smokejumperit/Smokejumper I T /ig;
    $text =~ s/\.?\s*kthn?xbye?\.?/.  K Thanks Bye./ig;
    $text =~ s/hpricot/hayprihcott/ig;
    $text =~ s/\bmins\b/minutes/ig;
    $text =~ s/\bttyl\b/talk to you later/ig;
    $text =~ s/\b<3\b/heart/ig;
    $text =~ s/\bcr+A+x?z+y\b/CRAZY/ig;
    $text =~ s/\.[\.\s]?\./.../ig;
    $text =~ s/(\d+)-+(\d+)/$1 to $2/ig;
    $text =~ s/\bgoto\b/go to/ig;
    $text =~ s/\b\+\b/plus/ig;
    $text =~ s/\b=\b/equals/ig;
    $text =~ s/\bocaml\b/O camel/ig;
    $text =~ s/\bjocaml\b/joe camel/ig;

    `say -v Victoria '$name.'; say -v Alex '$text.'`;
  }
}

Popularity: 6% [?]

5 Responses to “My TweetSpeak Update”

  1. [...] the previous post. I updated the source code to handle “ocaml”, “jocaml”, “+”, [...]

  2. Hamlet D'Arcyon 03 Apr 2008 at 6:57 pm

    darn you kids and your fancy lingo. in my day, FTW most certainly did not mean “for the win”. no wonder no one thinks my “punks not dead. FTW” tattoo is cool anymore.

  3. Billon 04 Apr 2008 at 11:23 am

    Hamlet - I always thought it meant F*** the world! What does it mean in relation to your tatoo?

  4. Robert Fischeron 07 Apr 2008 at 11:41 am

    Okay, I may need to start a Google Code repository for this. It’s changing pretty regularly as I bump into new stuff to add.

  5. [...] had a bunch of people join Twitter, and that was kind of neat, particularly when hooked up to TweetSpeak — it was like the last Monday of the month all the time. I got lots of good tips about [...]

Trackback URI | Comments RSS

Leave a Reply

Green Web Hosting! This site hosted by DreamHost.