def get_contacts_by_uids(uids): # Build query queries = [] for i in uids: q = BookQuery.field_test(ContactField.UID, BookQueryTest.IS, i) queries.append(q.to_string()) query = "(or {})".format(' '.join(queries)) r, cons = abook.get_contacts_sync(query, None) if r: return cons return []
def make_query_test_any_number_exist(numbers): queries = [] for n in numbers: q = BookQuery.vcard_field_test('TEL', BookQueryTest.CONTAINS, n) queries.append(q.to_string()) return "(or {})".format(' '.join(queries))
PHONE_PROPS = ( 'primary-phone', 'mobile-phone', 'business-phone', 'home-phone', 'business-phone-2', 'home-phone-2', 'company-phone', 'other-phone', 'assistant-phone', 'callback-phone', 'car-phone', 'pager' ) SEXP_ANY = BookQuery.any_field_contains('').to_string() registry = EDataServer.SourceRegistry.new_sync(None) source = registry.ref_builtin_address_book() abook = EBook.BookClient.new(source) abook.open_sync(False, None) def get_first_phone(contact): for p in PHONE_PROPS: prop = contact.get_property(p) if prop: return prop def get_repr_name(contact): ''' Get name to represent. May be name or phone number or email '''