Friday, March 30, 2012

Port your GTalk contacts to another account

Porting your GTalk contacts to another GTalk account is not as easy as the export-import feature of Gmail Contacts would have you believe. For, your GTalk accounts are only a subset of your Gmail ones. So, essentially, if you'd export all your contacts to a csv file from your Account #1 and import them to your Account #2, they would get imported but do not appear in your Gtalk.

I've been using Pidgin since many years now and I never knew it'd store all the contacts it imported in an xml file locally, with groups they belong to, their buddy icons, last seen time, etc.,  ~/.purple/blist.xml is where all these are present.

Steps


1. Install Pidgin, create accounts for both your gmail ids.
2. Open your Ruby console/irb and run the following code

# Parse the xml document...
doc = REXML::Document.new(File.read("/home/YOUR_USERNAME/.purple/blist.xml"))

# Initialize empty arrays
contacts_1 = []
contacts_2 = []

# Get all your contacts in your account number 1, assume it as account_1@gmail.com
doc.elements.each('//buddy[starts_with(@account,"account_1@gmail.com")]/name') {|e| contacts_1 << e.text}

# Get all your contacts in your account number 2, assume it as account_2@gmail.com
doc.elements.each('//buddy[starts_with(@account,"account_2@gmail.com")]/name') {|e| contacts_2 << e.text}

# Get the email ids of all contacts which are present in account#2 but not in account#2
# i.e., the contacts who need to be invited
(contacts_2 - contacts_1).join(", ")


3. You'll get some thing like this as output of the last line of code...
4. multiple contacts can be invited at once using Windows GTalk. So, open it and paste this output into the Invite Contacts wizard as shown below

That's it! You have the requests sent to all your invitees from your new account.

No comments: