Skip to content

Instantly share code, notes, and snippets.

@w0w
Created September 29, 2014 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save w0w/84f1f0ef1ebc759d0cf1 to your computer and use it in GitHub Desktop.
Save w0w/84f1f0ef1ebc759d0cf1 to your computer and use it in GitHub Desktop.
import atom.data
import gdata.data
import gdata.contacts.client
import gdata.contacts.data
# ...
def create_contact(gd_client):
new_contact = gdata.contacts.data.ContactEntry()
# Set the contact's name.
new_contact.name = gdata.data.Name(
given_name=gdata.data.GivenName(text='Elizabeth'),
family_name=gdata.data.FamilyName(text='Bennet'),
full_name=gdata.data.FullName(text='Elizabeth Bennet'))
new_contact.content = atom.data.Content(text='Notes')
# Set the contact's email addresses.
new_contact.email.append(gdata.data.Email(address='liz@gmail.com',
primary='true', rel=gdata.data.WORK_REL, display_name='E. Bennet'))
new_contact.email.append(gdata.data.Email(address='liz@example.com',
rel=gdata.data.HOME_REL))
# Set the contact's phone numbers.
new_contact.phone_number.append(gdata.data.PhoneNumber(text='(206)555-1212',
rel=gdata.data.WORK_REL, primay='true'))
new_contact.phone_number.append(gdata.data.PhoneNumber(text='(206)555-1213',
rel=gdata.data.HOME_REL))
# Set the contact's IM address.
new_contact.im.append(gdata.data.Im(text='liz@gmail.com',
primary='true', rel=gdata.data.HOME_REL, protocol=gdata.data.GOOGLE_TALK_PROTOCOL))
# Set the contact's postal address.
new_contact.structured_postal_address.append(
rel=gdata.data.WORK_REL, primary='true',
street=gdata.data.Street(text='1600 Amphitheatre Pkwy'),
city=gdata.data.City(text='Mountain View'),
region=gdata.data.Region(text='CA'),
postcode=gdata.data.PostCode(text='94043'),
country=gdata.data.Country(text='United States'))
# Send the contact data to the server.
contact_entry = gd_client.CreateContact(new_contact)
print "Contact's ID: %s" % contact_entry.id.text
return contact_entry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment