Created
July 26, 2011 11:57
-
-
Save jnwhiteh/1106586 to your computer and use it in GitHub Desktop.
Update contacts using Google contacts API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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