Never been to DZone Snippets before?

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

Using phonebook(contact) database (See related posts)

Now you can access and modify your mobile phone
contact database. Add new person, phone, email, etc.
Here's a short example
   1  
   2  import contacts
   3  db = contacts.open()
   4  
   5  all_ids = db.keys() # [159, 161, 273, ...]
   6  c = db[159]  # first contact
   7  found = db.find('jim')  # search in name, email, etc.
   8  jim = found[0]  # first one found
   9  
  10  jim_id = jim.id  # 819
  11  mobile = jim.find('mobile_number')[0].value  # first only
  12  firstname = jim.find('first_name')[0].value
  13  # other fields: email_address, url, company_name, job_title, 
  14  # phone_number, fax_number, note, etc.
  15  
  16  # to add new contact
  17  newc = db.add_contact()
  18  newc.add_field('first_name', 'Korakot')
  19  newc.add_field('mobile_number', '017337330')
  20  newc.commit()

Group infomation is missing, though.

Comments on this post

ildg posts on Jul 06, 2005 at 05:52
where is contacts module?
I can't import it.
gigi2600 posts on Mar 12, 2006 at 06:26
Hi Sir,
but the exact code is:
newc.add_field('first_name', 'Korakot')
newc.add_field('mobile_number', '017337330')

You need to create an account or log in to post comments to this site.


Click here to browse all 5551 code snippets

Related Posts