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.'`;
}
}
Related posts:
- Yet Another Reason
final is Your Friend
- LOLCode Update
- Real Life Update and Administrivia
- I’m on Twitter: RobertFischer
- Collective Update
Pingback: Enfranchised Mind » Updated TweetSpeak Again
Pingback: Enfranchised Mind » Twitter and I Aren’t Friends Anymore