DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Using Phonebook(contact) Database

06.09.2005
| 7120 views |
  • submit to reddit
        Now you can access and modify your mobile phone
contact database. Add new person, phone, email, etc.
Here's a short example
import contacts
db = contacts.open()

all_ids = db.keys() # [159, 161, 273, ...]
c = db[159]  # first contact
found = db.find('jim')  # search in name, email, etc.
jim = found[0]  # first one found

jim_id = jim.id  # 819
mobile = jim.find('mobile_number')[0].value  # first only
firstname = jim.find('first_name')[0].value
# other fields: email_address, url, company_name, job_title, 
# phone_number, fax_number, note, etc.

# to add new contact
newc = db.add_contact()
newc.add_field('first_name', 'Korakot')
newc.add_field('mobile_number', '017337330')
newc.commit()
Group infomation is missing, though.    

Comments

Snippets Manager replied on Sun, 2006/03/12 - 7:22am

Hi Sir, but the exact code is: newc.add_field('first_name', 'Korakot') newc.add_field('mobile_number', '017337330')

Snippets Manager replied on Mon, 2012/05/07 - 2:12pm

where is contacts module? I can't import it.