Syncing friends between Twitter accounts

Recently, I’ve created a new Twitter account. The reason for this is that I’m thinking of having a public account instead of, or maybe along side of, a private account. So, I’m testing it out to see if having a public account is something I really want to do or not.

So, I created a new account. After adding my design and icon, I realized that I had to follow people. So, I started following the people I’m following on my private account. This quickly became a task that I did not enjoy. So, I decided to write a script for it to make it a bit easier.

Below is the Perl script I created to handle this.


#!/usr/bin/perl

use Net::Twitter;
use Getopt::Long;
use strict;

# set your own username and password here
my $namefrom = '';
my $passfrom = '';
my $nameto = '';
my $passto = '';
GetOptions('namefrom=s' => \$namefrom, 'passfrom=s' => \$passfrom, 'nameto=s' => \$nameto, 'passto=s' => \$passto);

my $twitfrom = Net::Twitter->new(username=>$namefrom, password=>$passfrom);
my $twitto = Net::Twitter->new(username=>$nameto, password=>$passto);

# establish friends
if($twitfrom->friends()) {
  foreach my $friend (@{ $twitfrom->friends() }) {
        $twitto->follow($friend->{'id'});
  }
}

print "friends are synced between accounts\n";

I saved this file as sync_following.pl. So, now all I have to do is call the script with the options for my two accounts.

$./sync_following.pl --namefrom strimble --passfrom redacted --nameto _strimble --passto redacted

You can download it here. You’ll also need Net::Twitter and Getopt::Long.

Perl scripts make my twitter accounts much simpler to deal with. Let me know if you end up using this script too, and if it was helpful or not.

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • FriendFeed
  • Identi.ca
  • Netvibes
  • Reddit
  • StumbleUpon
  • ThisNext
  • Tumblr
  • Twitter

Post a Comment