Skip navigation

Tag Archives: abook

Following up with Retro Conversations, I’ve struggled yesterday for about 11 hours trying to find fetch a contact in address book using his/her number. I originally thought this would be an easy task, but it appears not as I found it that there are no python bindings for libabook yet.

I also found that the PyMaemo team were kind enough to write this tutorial on how to access APIs using ctypes for which there are no Python bindings yet that uses libosso-abook as an example. I read through the tutorial quickly which much of were very new to me and did not really understand.  So I  decided to explore Hermes’s source code to learn how it accesses contacts and I ended up writing this function:

def getContactNameFromPhone(self, phoneNum):
		addresses = evolution.ebook.open_addressbook('default')
		contacts = addresses.get_all_contacts()

		 #ai = GList.new(ebook.e_contact_get_attributes(hash(self._contact), E_CONTACT_EMAIL))

		for econtact in contacts:

			try:
				#print econtact.get_name()
				phones = econtact.get_property('phone')
				phones_p=int(str(phones)[13:-1],16)
				phoneList = GList.new(phones_p)

				while phoneList.has_next():
					currPhone = string_at(phoneList.next())

					if currPhone == phoneNum:
						return econtact.get_name()
			except:
				continue

which works, but if you examine the code, you’ll find that this is the worst solution ever! The app now takes about 2 or 3 minutes to start up. I also borrowed pygobject.py from Hermes to use its GList that is based on the PyMaemo tutorial I mentioned above.  I’m pretty sure things can be much simpler, I just didn’t get the whole ctypes things yet.. I guess I’m going to spend this night reading that PyMaemo tutorial again

Advertisements