Wednesday, August 22, 2007

Minimalistic Evolution phonebook extractor

If you're using Evolution as your E-Mail client and contact management application, and you like Python, here is a small snippet that allows you to dump out all phone numbers of your contacts to the console. Of course, with this code as a guide, you can produce even more useful applications ;)

What you need: Evolution, pygobject, evolution-python, Python (2.4 or higher) and some contacts in your contact list
#!/usr/bin/python

import evolution
import gobject

book = evolution.open_addressbook('default')

props = gobject.list_properties( evolution.EContact)
pp = [ p.name for p in props if 'phone' in p.name ]

for contact in book.get_all_contacts():
gp = contact.get_property
name = gp('file-as')
numbers = ', '.join( [ gp(p) for p in pp if gp(p) ])
if numbers:
print ': '.join( [ name, numbers ])

2 comments:

Dernalis said...

Nice guide, thanks a lot....

but I'm going crazy to get data from GParamBoxed data like 'birth-date'

could you add some stuff like this to source code?

thp said...

I'm now using an improved version of this code in smpy, which can be found here: http://thpinfo.com/2007/hacks/#smpy