Friday, October 09, 2009

Download compete twitter timeline

Upon popular request, I wrote a small script to download all tweets of a given twitter id. Have fun!


#!/usr/bin/perl

use Net::Twitter;
$|=1;

unless(@ARGV){
print "Usage: $0 twitter_id [sleep_seconds]\n";
exit 0;
}

my ($follow,$sleeper) = @ARGV;

# No account needed for this.
my $twit = Net::Twitter->new(username => 'MYNAME', password => 'XXX');

$p=1;
while(1){
my $result = $twit->user_timeline({id => $follow, page => $p});

foreach my $tweet (@{$result}){
print "At ", $tweet->{'created_at'},"\n";
print $tweet->{'text'},"\n\n";
}
++$p;
sleep $sleeper if $sleeper;
}


You might have to install the Net::Twitter module. This is most easily done as


sudo perl -MCPAN -e shell


and then (possibly after answering a few questions)


install Net::Twitter

2 comments:

Rick said...

could you pls. document also what I would have to change in this script to download all tweets from e.g. @abc123 (which is not me, so I do not have a login on him)

Robert said...

that script used to work for that (you could give an account name on the command line).

Since publishing it, twitter has however changed its API and now requires OAuth. You would have to get this to work (there are perl modules for this as well but this requires some work).