Reply
Thread Tools
blubbi's Avatar
Posts: 288 | Thanked: 113 times | Joined on Dec 2009 @ Germany
#1
Hi all,

I need to generate a list of contactas and a corresponding list with phone numbers for my program www2sms.

So far I came up with this solution:
Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
import evolution

name_attributes = [
	"full-name",
	"given-name",
	"family-name",
	"nickname"
]

phone_attributes = [
	"assistant-phone",
	"business-phone",
	"business-phone-2",
	"business-fax",
	"callback-phone",
	"car-phone",
	"company-phone",
	"home-phone",
	"home-phone-2",
	"home-fax",
	"isdn-phone",
	"mobile-phone",
	"other-phone",
	"other-fax",
	"pager",
	"primary-phone",
	"radio",
	"telex",
	"tty",
]

def on_Contact_clicked():
	single_contact = []
	single_contact_numbers = []
	contact_list = []
	phone_list = []
	
	abook = evolution.ebook.open_addressbook("default")
	contacts = abook.get_all_contacts()
	contacts.sort(key=lambda obj: obj.get_name())

	for econtact in contacts:
		#help(econtact)
		single_contact = [econtact.get_property(name_attributes[2]), econtact.get_property(name_attributes[1])]
		for phone_attribute in phone_attributes:
			single_contact_numbers.append(econtact.get_property(phone_attribute))
		contact_list.append(single_contact)
		phone_list.append(single_contact_numbers)
		single_contact = []
		single_contact_numbers = []

	ID = 0
	for contact in contact_list:
		print ID
		print "--> %s, %s" %(contact[0], contact[1])
		print "~~~> %s" %(phone_list[ID][11])
		ID += 1

on_Contact_clicked()
It works, except that only the attribute "mobile-phone" is fetched correctly, all other numbers are "None" (Just replace "print "~~~> %s" %(phone_list[ID][11])" with "print "~~~> %s" %(phone_list[ID])" and you'll see the mess...

Has anyone an idea?

Thanks a lot
Bjoern
 
blubbi's Avatar
Posts: 288 | Thanked: 113 times | Joined on Dec 2009 @ Germany
#2
Okay, I ran into another problem.

What happens if a contact hast more numbers assigned to the category "Mobile" or "Mobile (home)" ....

In the case I showed above, only the last number for "Mobile" is shown.

So how to deal with multiple numbers assigned to one "category"

Any suggestions?

Cheers
Bjoern
 
Posts: 196 | Thanked: 54 times | Joined on Jan 2010 @ UK
#3
What happens if a contact hast more numbers assigned to the category "Mobile" or "Mobile (home)" ....

In the case I showed above, only the last number for "Mobile" is shown.
I get only the first mobile number, if I have more than one.

Did you find any solution to this?
 
blubbi's Avatar
Posts: 288 | Thanked: 113 times | Joined on Dec 2009 @ Germany
#4
Originally Posted by fred123 View Post
I get only the first mobile number, if I have more than one.

Did you find any solution to this?
Nope not yet.

If you use

Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
import evolution

def on_Contact_clicked():
    abook = evolution.ebook.open_addressbook("default")
    contacts = abook.get_all_contacts()
    #contacts.sort(key=lambda obj: obj.get_name())
    for econtact in contacts:
	numbers = econtact.get_property('phone')
	print numbers
	#--> <gpointer at 0x1bf4b0>

on_Contact_clicked()
you get back a pointer, and I don't know how to handle this one.

I am still stuck. Any hint, idea, solution is welcome

Desperately,
Bjoern
 
Posts: 15 | Thanked: 4 times | Joined on Mar 2010
#5
Is it normal I have no contacts returned by the method?


Code:
In [1]: import evolution
In [2]: abook = evolution.ebook.open_addressbook("default")

In [3]: type(abook)
Out[3]: <type 'ebook.EBook'>

In [4]: contacts = abook.get_all_contacts()

In [5]: type(contacts)
Out[5]: <type 'list'>

In [6]: contacts.sort(key=lambda obj: obj.get_name())

In [7]: contacts
Out[7]: []

In [20]: evolution.ebook.list_addressbooks()
Out[20]: []
 
blubbi's Avatar
Posts: 288 | Thanked: 113 times | Joined on Dec 2009 @ Germany
#6
Originally Posted by nthx View Post
Is it normal I have no contacts returned by the method?
No, "contacts" sould contain a list of contacts:
Code:
>>> contacts
[<ebook.EContact object at 0x4075f8f0 (EContact at 0x1ddf80)>,
<ebook.EContact object at 0x4075f210 (EContact at 0x1c1d78)>,
<ebook.EContact object at 0x4075fcb0 (EContact at 0x1de230)>,
<ebook.EContact object at 0x40761620 (EContact at 0x1f0bb0)>,
...
<ebook.EContact object at 0x4075f670 (EContact at 0x1dddb0)>,
<ebook.EContact object at 0x4075f3c8 (EContact at 0x1c1900)>,
<ebook.EContact object at 0x40761a30 (EContact at 0x1f0e90)>]
>>> len(contacts)
192
Sure you have contacts in your address book?

Kind regards
Bjoern
 
Posts: 15 | Thanked: 4 times | Joined on Mar 2010
#7
Hmm.. Maybe let's define "Addressbook" first to make it clear what it is..
I thought it's the app called "Contacts" with my ... eee... contacts I can call Isn't it?

So I have ~350 including Skype, Jabber..

I have installed python-evolution using plain:
apt-get install python-evolution.
It didn't come with python2.5 by default.


T.

Code:
Nokia-N900-51-1:~/.osso-abook$ pwd
/home/user/.osso-abook
Nokia-N900-51-1:~/.osso-abook$ /bin/ls
avatars  db       photos
Nokia-N900-51-1:~/.osso-abook$ /bin/ls db/
IMEI:356211000457518.changes.db  index_full_name.db
PC Suite Data Sync.changes.db    index_im_jabber.db
PC Suite.changes.db              index_last_first.db
addressbook.db                   index_phone.db
fre1.changes.db                  log.0000000001
index_email.db                   running_id.db
index_first_last.db              tp-cache
 
blubbi's Avatar
Posts: 288 | Thanked: 113 times | Joined on Dec 2009 @ Germany
#8
Did you try to run my code from my first or third post "exactly" just to be sure.

If this results in an empty list, something is wrong on your phone

Just paste the code into a file an run it directly on the phone.
 
Posts: 15 | Thanked: 4 times | Joined on Mar 2010
#9
I've found the reason...

=username

I log with different username, though the same UID as 'user'
That's the reason. Library can't find /home/*/.osso/*


When logged as 'user' I get proper results

Code:
Nokia-N900-51-1:~/MyDocs/.images/40d$ sudo gainroot
Root shell enabled


BusyBox v1.10.2 (Debian 3:1.10.2.legal-1osso26+0m5) built-in shell (ash)
Enter 'help' for a list of built-in commands.

/home/user/MyDocs/.images/40d # su - user
~ $ id
uid=29999(user) gid=29999(users)
~ $ ipython
In [1]: import evolution

In [2]: abook = evolution.ebook.open_addressbook("default")

In [3]: abook.get_all_contacts()
Out[3]: 
[<ebook.EContact object at 0x445cb0 (EContact at 0x4a7b50)>,
 <ebook.EContact object at 0x456f80 (EContact at 0x4a7b68)>,
 <ebook.EContact object at 0x456e40 (EContact at 0x4a7b80)>,

 
Posts: 15 | Thanked: 4 times | Joined on Mar 2010
#10
All right Bjoern - back to the topic...


Looks like on my phone your code is quite all right. It retrieves Phone (home) correctly from one of my addressbook contacts.


Code:
contacts = abook.get_all_contacts()
In [104]: me = [c for c in contacts if 'Tomasz' in str(c.get_name())][0]

In [105]: me
Out[105]: <ebook.EContact object at 0x457238 (EContact at 0x4a7d20)>

In [106]: me.get_name()
Out[106]: 'Tomasz'
In [109]: for p in phone_attributes:
    print p, me.get_property(p)
   .....:     
   .....:     
assistant-phone None
business-phone None
business-phone-2 None
business-fax None
callback-phone None
car-phone None
company-phone None
home-phone +4822****
home-phone-2 None
home-fax None
isdn-phone None
mobile-phone +48600****
other-phone +4822****
other-fax None
pager None
primary-phone None
radio None
telex None
tty None
So as you see, the function shows all my phones.

What is strange, is that in the contact itself I have only 2 phone numbers: Mobile and Phone (home).
But in the result from ebook...get_property(*) you can see 3 numbers returned.

I don't know why it gave 2 entries for the same phone number (other-phone == home-phone) It doesn't cause any trouble for me, so I'm all right with this..

Hope it helps.
And thanks to you for starting the post. I now can retrieve contact info based on the phone for my new apps .. :-D


Tomasz
 
Reply


 
Forum Jump


All times are GMT. The time now is 03:59.