Created
September 8, 2011 23:01
-
-
Save fsouza/1205025 to your computer and use it in GitHub Desktop.
Removes prefix to your contacts on Google Contacts
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
# -*- coding: utf-8 -*- | |
import gdata.contacts.client | |
import gdata.contacts.data | |
USER = "" | |
PASSWD = "" | |
PREFIX = '041' | |
def add_prefix_to_contacts(gd_client, prefix): | |
query = gdata.contacts.client.ContactsQuery() | |
query.max_results = 10000 | |
feed = gd_client.get_contacts(q=query) | |
len(feed.entry) | |
for entry in feed.entry: | |
if entry.phone_number: | |
print "Updating %s... " % entry.name.full_name.text, | |
for i, phone_number in enumerate(entry.phone_number): | |
the_number = phone_number.text | |
if the_number.startswith('041'): | |
the_number = "0%s" % the_number[3:] | |
if the_number.startswith('+55'): | |
the_number = the_number.replace('+55', '0') | |
the_number = the_number.replace("-", "") | |
entry.phone_number[i].text = the_number | |
gd_client.Update(entry) | |
print "ok" | |
if __name__ == '__main__': | |
gd_client = gdata.contacts.client.ContactsClient(source='GoogleInc-ContactsPythonSample-1') | |
gd_client.ClientLogin(USER, PASSWD, gd_client.source) | |
add_prefix_to_contacts(gd_client, prefix=PREFIX) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment