Net::Twitter goodness
Some of us has recently become addicted to Twitter. As I discovered that someone has already made a Net::Twitter Perl module, the natural extension of this lunacy was to integrate Twitter support into our LED sign. We created a common Twitter account, to which we added as friends all the team members that wished to participate. With just a few lines of Perl code, we then got our tweets prominently displayed on the team LED sign. Pure Web 2.0 goodness!
my $twit = Net::Twitter->new(username=>"foo", password=>"bar" );
my @seentweets;
sub fetchtwits() {
my $timeline = $twit->friends_timeline();
my $firsttime = @seentweets ? 0 : 1;
return "" unless $timeline;
TWEET: for (@{$timeline}) {
my %tweet = %{$_};
if ($firsttime) {
# if this is the first time we're running, just
# populate the seen list with all tweets so that
# we don't spew out the whole timeline on startup
push @seentweets, $tweet{'id'};
}
for (@seentweets) {
if ($_ eq $tweet{'id'}) {
next TWEET;
}
}
my %user = %{$tweet{'user'}};
my $msg = '<GD1>' . $user{'screen_name'} . ": " . $tweet{'text'};
print "new tweet: " . $msg . " [" .$tweet{'id'} . "]\\n";
toled('A', $msg);
push @seentweets, $tweet{'id'};
return $msg;
}
return "";
}