11
11
import os
12
12
13
13
# List of properties to be ignored.
14
- IGNORED_PROPS = ["com.apple.ABPersonMeProperty" , "ABPersonFlags" , "com.apple.ABImageData" ,]
14
+ IGNORED_PROPS = ["com.apple.ABPersonMeProperty" , "ABPersonFlags" ,
15
+ "com.apple.ABImageData" ,
16
+ "com.apple.ABGroupMembersProperty" ,
17
+ ]
15
18
16
19
def getAddressBook ():
17
20
"""
@@ -23,23 +26,40 @@ def all():
23
26
"""
24
27
Returns all the people from the addressbook.
25
28
"""
26
- peopleList = []
27
- allPeople = getAddressBook ().people ()
28
- for people in allPeople :
29
- aperson = {}
30
- for prop in people .allProperties ():
29
+ return _clist (getAddressBook ().people ())
30
+
31
+ def _clist (slist ):
32
+ """
33
+ Method to convert NSArray to python list
34
+ """
35
+ retList = []
36
+ for p in slist :
37
+ aobj = {}
38
+ for prop in p .allProperties ():
31
39
if prop in IGNORED_PROPS :
32
40
continue
33
- tmpval = people .valueForProperty_ (prop )
41
+ tmpval = p .valueForProperty_ (prop )
34
42
if type (tmpval ) == ABMultiValueCoreDataWrapper :
35
43
aval = [_getVal (tmpval .valueAtIndex_ (i )) for i in range (0 , tmpval .count ())]
36
44
else :
37
- aval = _getVal (tmpval )
45
+ aval = _getVal (tmpval )
38
46
if aval is not None :
39
- aperson [prop .lower ()] = aval
40
- peopleList .append (aperson )
41
- return peopleList
47
+ aobj [prop .lower ()] = aval
48
+ retList .append (aobj )
49
+ return retList
42
50
51
+ def groups ():
52
+ """
53
+ Return groups
54
+ """
55
+ return _clist (getAddressBook ().groups ())
56
+
57
+ def me ():
58
+ """
59
+ Returns the current logged in user.
60
+ """
61
+ return _clist ([getAddressBook ().me ()])[0 ]
62
+
43
63
def _getVal (tmpval ):
44
64
"""
45
65
Extract value from unicode or Date object.
@@ -52,10 +72,12 @@ def _getVal(tmpval):
52
72
elif type (tmpval ) == NSCFDictionary :
53
73
aval = dict ([(k .lower (), tmpval [k ]) for k in tmpval .keys ()])
54
74
return aval
55
-
56
- def main ():
57
- all ()
58
75
76
+ def main ():
77
+ #print all()
78
+ #print groups()
79
+ print me ()
80
+
59
81
if __name__ == '__main__' :
60
82
main ()
61
83
0 commit comments