stepping away from google contacts

in my previous blog post, i briefly talked about syncing an android phone with icloud instead of google contacts. in this post, i’ll talk a little bit about cleaning up your google contacts.

so if you’re like me, you may not be quite ready to erase everything from google contacts (because the implicit result of this is that you will lose google chat access to these people (unless you request permission to chat with them again), and i believe you may also break google plus connections, but i am not certain about that one).

rather than cleaning up manually (which could take a long time, depending on the number of contacts you have), here is a way to start the clean up process.

  1. download googlecl. this open source project allows you to send commands to certain google services from the command line.
  2. download the gdata-python-client library. this is required to run googlecl.
  3. install both (untar, then sudo python setup.py install on both).

now validate that it works - a good test would be running google contacts list ahmed, to list any ahmeds you have in your contacts. this should open up a browser the first time to ask you to authenticate googlecl to use your account info.

now that we’re validated and authenticated, we can start doing things like this:

for i in `perl -e '$,=" ";print +(A..Z)'`; do
   google contats list --fields=name,email,phone $i\* >> contacts;
   # perhaps put a sleep here just to be safe and not get locked out.
done

the first part enumerates A-Z (got that bit from stackoverflow) - so for each character between A and Z, get all the names, emails, and phone numbers of my contacts. note that this causes certain records to appear many times, and i am not sure if there’s a better way to do this - perhaps just looping on a, e, i, o, u would suffice, but i am not sure.

now, you can do things like this:

# pull out unique contacts
cat contacts | sort | uniq > unique.contacts

# save contacts with no email address in a file for deletion
cat unique.contacts | grep ,None, | cut -f 1 -d ',' > to.delete

# save non-gmail contacts for deletion
cat unique.contacts | grep -v ',None,' | grep -v gmail | grep -v googlemail |
  cut -f 1 -d ',' >> to.delete

# delete them
while read line
do
   echo 'y' | google contacts delete "$line"
   # perhaps add a sleep here if you're afraid of rate limit/lock out
done < to.delete

and there you have it. eventually, i’ll remove everyone from google contacts, but for now, this greatly reduces the number of people in google contacts that don’t need to be there.

that’s all for now!