Skip to content

Instantly share code, notes, and snippets.

@jnwhiteh
Created July 26, 2011 11:57
Show Gist options
  • Save jnwhiteh/1106586 to your computer and use it in GitHub Desktop.
Save jnwhiteh/1106586 to your computer and use it in GitHub Desktop.
Update contacts using Google contacts API
import atom
import re
import gdata.contacts.data
import gdata.contacts.client
import gdata.gauth
# This script updates all contacts with email addresses @comlab.ox.ac.uk to
# @cs.ox.ac.uk to go along with the renaming of our department.
sourcename = "some-name-for-this-script-v1"
email = "[email protected]"
passwd = "yourpassword"
client = gdata.contacts.client.ContactsClient(source=sourcename)
client.ClientLogin(email, passwd, client.source)
query = gdata.contacts.client.ContactsQuery()
query.max_results = 2000
# Add some query data here to limit the results you get
feed = client.GetContacts(q = query)
for i, entry in enumerate(feed.entry):
for email in entry.email:
if re.search(".*@comlab.ox.ac.uk", email.address) != None:
converted = re.sub("(comlab.ox.ac.uk)", "cs.ox.ac.uk", email.address)
print "Updating %s -> %s" % (email.address, converted)
email.address = converted
client.Update(entry)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment