Here's a quick way to get the last 10 Twitter messages (Tweets?) from the MarsPhoenix lander. The script requires XML::RSS::Parser::Lite, but I have no doubt that there are lots of other ways to do it.

I threw this together quickly for my wife after she read today's NYTimes article on the lander's use of Twitter. We're not cool enough to actually do Twitter, so this is an easy way to get her some recent messages. (Sure, she could just add the RSS feed itself to a browser or aggregator, but that wouldn't be using Perl, now would it?)

At the moment, the script is pretty minimal, but it would be easy to format more from here for inclusion in an email, etc. Check it out if you're curious.

#!/usr/bin/perl use strict; use warnings; use XML::RSS::Parser::Lite; use LWP::Simple; my $xml = get( "http://twitter.com/statuses/user_timeline/14693823.rss" ); die "No connection to MarsPhoenix. Try later.\n" unless defined $xml; my $rss = new XML::RSS::Parser::Lite; $rss->parse( $xml ); print $rss->get( 'title' ) . " - Last ten updates from MarsPhoenix:\n" +; foreach my $number ( 0..9 ) { my $item = $rss->get( $number++ ); print $item->get( 'title' ) . "\n"; }

Replies are listed 'Best First'.
Re: Get updates from MarsPhoenix via Twitter & Perl
by blazar (Canon) on Jun 02, 2008 at 14:12 UTC
    foreach my $number ( 0..9 ) { my $item = $rss->get( $number++ );

    I personally believe that $number++ does nothing there.

    --
    If you can't understand the incipit, then please check the IPB Campaign.
      It's not just you that thinks so: the ++ is useless. Thanks for pointing it out. It's a relic of a first thought (I think), where I counted up in a while loop. In the end, a for loop made more sense, but I kept incrementing $number just for fun. (Translation: I completely lost track of what I was doing there, but Perl was nice enough to Do What I Meant (TM) anyhow.