I want to copy my gmail contacts to my wife’s account. Ideally I would like to share them like I share my online calendar but Google provides no mechanism for this. That is annoying.
So annoying, in fact, that it sparked a hulk-like welling up of my inner geek and the production of this python code to at least do the copying. It doesn’t sync or share, it just copies.
It’s a blunt instrument, but it does the job.
# -*- coding: utf-8 -*- import atomimport gdata.contactsimport gdata.contacts.serviceimport gdata.data gmailuser1="source gmail user"gmailpw1="source gmail password"gmailuser2="destination gmail user"gmailpw2="destination gmail password" print "Connecting to gmail as "+gmailuser1; gml1 = gdata.contacts.service.ContactsService()gml1.email = gmailuser1gml1.password = gmailpw1gml1.source = 'Ponstructor-GmailCtctCopy-1.0'gml1.ProgrammaticLogin() print "Connecting to gmail as "+gmailuser2 gml2 = gdata.contacts.service.ContactsService()gml2.email = gmailuser2gml2.password = gmailpw2gml2.source = 'Ponstructor-GmailCtctCopy-1.0'gml2.ProgrammaticLogin() print "Obtaining contacts feed from "+gmailuser1feedquery = gdata.contacts.service.ContactsQuery()feedquery.max_results = 9999gmlfeed = gml1.GetContactsFeed(feedquery.ToUri()) print "Adding contacts to "+gmailuser2for index,gmlctct in enumerate(gmlfeed.entry): if gmlctct.title.text != None: print "Adding "+gmlctct.title.text setattr(gmlctct,'group_membership_info',None) setattr(gmlctct,'id',None) setattr(gmlctct,'link',None) try: entry = gml2.CreateContact(gmlctct) except gdata.service.RequestError,err: if err.args[0]["status"]==409: print "Conflict - that's fine keep moving" elif err.args[0]["status"]==400: print "Bad Request - can't do much about it" else: raise err






Geek, indeed!