Exemple #1
0
def script2():
    # create new, empty database.
    db = contacts.open('test_database', 'n')

    # add new contact.
    contact = db.add_contact()
    contact.add_field('first_name', value='John', label='Nickname')
    contact.add_field('last_name', 'Doe')
    contact.add_field('date', time.time())
    contact.add_field('mobile_number', '76476548', 'work')
    contact.add_field(type='mobile_number', value='8764573', location='home')
    contact.commit()

    # print contact's data.
    for entry_id in db:
        contact = db[entry_id]
        print '**********'
        print 'the contact:%s' % contact
        print 'entry\'s id:%s' % contact.id
        print 'last_modified:%s' % time.ctime(contact.last_modified)
        print 'number of fields:%s' % len(contact)
        print 'field data:'
        print '----------'
        for field in contact:
            print 'label:%s' % field.label
            if field.schema['storagetype'] == 'datetime':
                print 'value:%s' % time.ctime(field.value)
            else:
                print 'value:%s' % field.value
            print 'type:%s' % field.type
            print 'location:%s' % field.location
            print '----------'
def script4():
    # open the database..
    db = contacts.open(u'test_database_3', 'n')

    # add new contacts
    contact1 = db.add_contact()
    contact1.add_field(contacts.first_name, u'Bill', u'Nickname')
    contact1.add_field(contacts.last_name, u'Mason')
    contact1.commit()

    contact2 = db.add_contact()
    contact2.add_field(contacts.first_name, u'Julie')
    contact2.add_field(contacts.last_name, u'Richards')
    contact2.add_field((contacts.phone_number_mobile, contacts.location_work),
                       u'76476547')
    contact2.add_field((contacts.phone_number_mobile, contacts.location_home),
                       u'76476548')
    contact2.commit()

    id1 = contact1.entry_data()["uniqueid"]
    id2 = contact2.entry_data()["uniqueid"]

    vcards = db.export_vcards(
        (id1, id2), contacts.vcard_exclude_uid | contacts.vcard_include_x)

    print vcards

    db.close()
Exemple #3
0
def script3():
    # open the database, create if does not exist.
    db = contacts.open('test_database', 'c')

    # add new contact.
    contact = db.add_contact()

    # delete all the default fields
    while len(contact):
        del contact[0]

    # add new fields
    contact.add_field('first_name', value='John', label='Nickname')
    contact.add_field('last_name', 'Doe')
    contact.commit()

    print 'the contact at first:%s' % contact

    # modify the first of 'first_name' fields.
    contact.find('first_name')[0].value = 'Henry'

    print 'the contact now:%s' % contact

    # delete the first of 'first_name' fields.
    del contact[contact.find('first_name')[0].index]

    print 'and now:%s' % contact

    # delete the contact.
    del db[contact.id]
Exemple #4
0
def script6():
    # open and empty the database, create if does not exist.
    db = contacts.open('test_database', 'n')

    # get available field types.
    fieldtypes = db.field_types()

    # add new contacts.
    contact1 = db.add_contact()
    contact1.add_field('first_name', value='Bill', label='Nickname')
    contact1.add_field('last_name', value='Mason')
    contact1.add_field('country', 'United States')
    contact1.commit()

    contact2 = db.add_contact()
    contact2.add_field('first_name', 'Julie')
    contact2.add_field('last_name', 'Richards')
    contact2.add_field('country', 'Canada')
    contact2.commit()

    # search by string.

    print 'search results for \'ichar\':'
    search_results = db.find('ichar')
    print search_results
    print ''

    print 'search results for \'i\':'
    search_results = db.find('i')
    print search_results
    print ''
Exemple #5
0
def script3():
    # open the database, create if does not exist.
    db=contacts.open('test_database','c')
    
    # add new contact.
    contact=db.add_contact()

    # delete all the default fields
    while len(contact):
        del contact[0]

    # add new fields
    contact.add_field('first_name',value='John',label='Nickname')
    contact.add_field('last_name','Doe')
    contact.commit()
    
    print 'the contact at first:%s'%contact
    
    # modify the first of 'first_name' fields.
    contact.find('first_name')[0].value='Henry'
    
    print 'the contact now:%s'%contact
    
    # delete the first of 'first_name' fields.
    del contact[contact.find('first_name')[0].index]
    
    print 'and now:%s'%contact
    
    # delete the contact.
    del db[contact.id]
def script3():
    # open the database..
    db = contacts.open(u'test_database_2', 'c')

    # add new contact
    contact = db.add_contact()
    contact.add_field(contacts.first_name, u'John', u'Nickname')
    contact.add_field(contacts.last_name, u'Doe')
    contact.commit()

    print u'the contact at first:%s' % contact

    # modify the contact
    contact.begin()
    contact.modify_field(
        0, u'Henry'
    )  # 0 is the index of the field. this is ugly but i think this is more easily fixed in python wrapper.

    print u'the contact now:%s' % contact

    # delete the first field
    del contact[0]

    contact.commit()

    print u'and now:%s' % contact

    # delete the contact
    del db[contact.entry_data()["uniqueid"]]

    db.close()
Exemple #7
0
def script2():
    # create new, empty database.
    db=contacts.open('test_database','n')
       
    # add new contact.
    contact=db.add_contact()
    contact.add_field('first_name',value='John',label='Nickname')
    contact.add_field('last_name','Doe')
    contact.add_field('date',time.time())
    contact.add_field('mobile_number','76476548','work')
    contact.add_field(type='mobile_number',value='8764573',location='home')
    contact.commit()

    # print contact's data.
    for entry_id in db:
        contact=db[entry_id]
        print '**********'
        print 'the contact:%s'%contact
        print 'entry\'s id:%s'%contact.id
        print 'last_modified:%s'%time.ctime(contact.last_modified)
        print 'number of fields:%s'%len(contact)
        print 'field data:'
        print '----------'
        for field in contact:
            print 'label:%s'%field.label
            if field.schema['storagetype']=='datetime':  
                print 'value:%s'%time.ctime(field.value)
            else:
                print 'value:%s'%field.value
            print 'type:%s'%field.type
            print 'location:%s'%field.location
            print '----------'
Exemple #8
0
 def test_import_export_vcard(self):
     # Testing importing and exporting vcard.
     contact_obj = self.add_contacts()
     # Export all the contacts in db database to vcards
     vcards = self.db.export_vcards(tuple(self.db.keys()))
     # Open a temporary database to which the contacts will be imported.
     temp_db = contacts.open('db_temp', 'n')
     # Import the same vcard into temp_db database and check if the fields
     # are matching in their values
     temp_db.import_vcards(vcards)
     db_id = self.db.keys()[0]
     try:
         for ids in temp_db.keys():
             if ids == db_id:
                 if not (temp_db[ids].find('first_name')[0].value
                         == self.db[db_id].find('first_name')[0].value
                         and temp_db[ids].find('last_name')[0].value
                         == self.db[db_id].find('last_name')[0].value and
                         temp_db[ids].find('mobile_number', 'home')[0].value
                         == self.db[db_id].find('mobile_number',
                                                'home')[0].value and
                         temp_db[ids].find('mobile_number', 'work')[0].value
                         == self.db[db_id].find('mobile_number',
                                                'work')[0].value):
                     self.fail("Import and export functionality \
                                not working")
     finally:
         for id in temp_db:
             del temp_db[id]
         del temp_db
Exemple #9
0
def script7():
    # open and empty the database, create if does not exist.
    db=contacts.open('test_database','n')

    # add a contact.
    contact=db.add_contact()

    # delete all the default fields
    while len(contact):
        del contact[0]
        
    contact.add_field('first_name',value='Bill',label='Nickname')
    contact.add_field('last_name',value='Mason')
    contact.commit()

    # get first of contact's 'first_name' fields.
    field=contact.find('first_name')[0] 
    field.value='Jack' # change the name.

    print db[contact.id] # autocommit is on (since the name has changed in the database).

    contact.begin()
    field.value='John'
    print db[contact.id] # autocommit is off (since the name has not changed in the database).
    contact.commit() # save the changes.

    print db[contact.id] # commit() saved the changes (since the name has changed in the database).

    field.value='Henry'
    print db[contact.id] # autocommit is on again (since the name is changed in the database).
Exemple #10
0
def script6():
    # open and empty the database, create if does not exist.
    db=contacts.open('test_database','n')

    # get available field types.
    fieldtypes=db.field_types()
    
    # add new contacts.
    contact1=db.add_contact()
    contact1.add_field('first_name',value='Bill',label='Nickname')
    contact1.add_field('last_name',value='Mason')
    contact1.add_field('country','United States')
    contact1.commit()
    
    contact2=db.add_contact()
    contact2.add_field('first_name','Julie')
    contact2.add_field('last_name','Richards')
    contact2.add_field('country','Canada')
    contact2.commit()

    # search by string.
    
    print 'search results for \'ichar\':'
    search_results=db.find('ichar')
    print search_results
    print ''
    
    print 'search results for \'i\':'
    search_results=db.find('i')
    print search_results
    print ''  
Exemple #11
0
def ListContacts():
	db = contacts.open()
	names = []
	name = ''
	for id in db.keys():
		name = ''
		con = db[id]    # get the contact for each key
		if len(con.find('first_name')) >= 1:		# if first name set is >= 1 then first exists	
			name = name + str(con.find('first_name')[0].value) +' '
		if len(con.find('last_name')) >= 1:		# if first name set is >= 1 then first exists	
			name = name + str(con.find('last_name')[0].value) + ' '
		for mobile_num in con.find('mobile_number'):   	# get the mobile numbers in each contact
			name = name + '<' + str(mobile_num.value) + '>'	
		for mobile_num in con.find('phone_number'):   	# get the mobile numbers in each contact
			name = name + '<' + str(mobile_num.value) + '>'	
		names = names + [name]
	names.sort()
	'''
	i=0
	for name in names:
		print name[0:30] +'\t',
		i += 1
		if i%2 == 0: print 
	'''
	print '------------------------'
def script2():
    # create new, empty database
    db = contacts.open(u'test_database_1', 'n')

    # get available field types
    fieldtypes = db.field_types()

    # add new contact
    contact = db.add_contact()
    contact.add_field(contacts.first_name, value=u'John', label=u'Nickname')
    contact.add_field(contacts.last_name, u'Doe')
    contact.add_field(contacts.date, time.time())
    contact.add_field(contacts.phone_number_mobile, u'76476548')
    contact.commit()

    for entry_id in db:
        contact = db[entry_id]
        print u'the contact:%s' % contact
        print u'entry\'s data:%s' % contact.entry_data()
        print u'number of fields=%s' % len(contact)
        for field in contact:
            print u'the field label:%s' % field["label"]
            if (db.field_info(contact.field_info_index(field["fieldindex"]))
                ["storagetype"] == contacts.storage_type_datetime):
                print time.ctime(field["value"])
            else:
                print u'the field value:%s' % field["value"]

    db.close()
def search_name():
	db=contacts.open()
	my_contact = appuifw.query(u"name:", "text")
	print("-"*15)
	print ("search name: %s" %(my_contact,))
	result = db.find(my_contact)
	print result
	print("-"*15)
def script1():
    db = contacts.open()

    for entry_id in db:
        contact = db[entry_id]
        print u'the contact:%s' % contact

    db.close()
def script7():
    # open the database..
    db = contacts.open(u'test_database_3', 'n')

    field_types = db.field_types()

    print db.field_info(field_types.keys()[0])

    db.close()
Exemple #16
0
def script8():
    # open the database.
    db = contacts.open()

    # compact if required.
    if (db.compact_required()):
        db.compact()
        print 'compacting done'
    else:
        print 'no need to compact'
Exemple #17
0
def script8():
    # open the database.
    db=contacts.open()
    
    # compact if required.
    if(db.compact_required()):
        db.compact()
        print 'compacting done'
    else:
        print 'no need to compact'
Exemple #18
0
def find_number(sender):
    cdb = contacts.open()
    matches = cdb.find(sender)
    if matches:
        num = matches[0].find("mobile_number")
        if num:
            return num[0].value
        else:
            return None
    return sender
def search_number():
	db=contacts.open()
	my_number = appuifw.query(u"number:", "text")
	print("-"*15)
	print("number entered: %s" % (my_number,))
	for entry_id in db:
		for field in db[entry_id]:
			# suggestion: use field.mobile_number
			if my_number in repr(field.value):
				print("%s:%s" %(db[entry_id],field.value))
	print("-"*15)
Exemple #20
0
def script9():
    # open and empty the database, create if does not exist.
    db = contacts.open('test_database', 'n')

    # add a contact.
    contact = db.add_contact()
    contact.add_field('first_name', value='Bill', label='Nickname')
    contact.add_field('date', value=time.time())
    contact.commit()

    # print information about the field types.
    print contact.find('first_name')[0].schema
    print contact.find('date')[0].schema
Exemple #21
0
def script9():
    # open and empty the database, create if does not exist.
    db=contacts.open('test_database','n')

    # add a contact.
    contact=db.add_contact()
    contact.add_field('first_name',value='Bill',label='Nickname')
    contact.add_field('date',value=time.time())
    contact.commit()

    # print information about the field types.
    print contact.find('first_name')[0].schema
    print contact.find('date')[0].schema
Exemple #22
0
def retrieve_contacts():
    db = contacts.open()
    fh = open('E:\data\python\contacts.txt', 'w')
    fh.write(db.export_vcards(db.keys()))
    fh.close()
    for contact in db.find(''):
        fields = ['first_name', 'last_name', 'mobile_number']
        find_values = [contact.find(field) for field in fields]
        values = [field_values[0].value if field_values else '' for field_values in find_values]
        print contact.id,
        for value in values:
            print value,
        print
Exemple #23
0
def selectnum():
    global n
    db = contacts.open()
    names = []
    numbers = []
    for i in db:
        names.append(db[i].title)
        num = db[i].find("mobile_number")
        if num:
            numbers.append(num[0].value)
        else:
            numbers.append(None)
    i = appuifw.selection_list(names)
    n = numbers[i]
Exemple #24
0
def get_contacts_info(contacts_list, name_order):
    log(">> get_contacts_info")
    info_list = []
    # open database
    db = contacts.open()
    
    field1 = u''
    field2 = u''
    
    if name_order == "0":
        field1 = u'first_name'
        field2 = u'last_name'
    elif name_order == "1":
        field2 = u'first_name'
        field1 = u'last_name'
    
    # add info into list
    for i in contacts_list:
        info = []
        # hlight_index
        info.append(i[2])
        
        # make fullname
        title = u''
        if db[i[0]].find(field1):
            title = unicode(db[i[0]].find(field1)[0].value)
        if db[i[0]].find(field2):
            title += u' ' + unicode(db[i[0]].find(field2)[0].value)

        # fullname
        info.append(title.strip(u' '))
        
        # mobile number
        if db[i[0]].find(u'mobile_number'):
            for num in db[i[0]].find(u'mobile_number'):
                if len(num.value) > 0: info.append(unicode(num.value))

        # phone number
        if db[i[0]].find(u'phone_number'):
            for num in db[i[0]].find(u'phone_number'):
                if len(num.value) > 0: info.append(unicode(num.value))
        
        # info(hlight_index, fullname, mobile, phone)
        info_list.append(info)

    # return list
    print "info_list: " + repr(info_list)
    return info_list
Exemple #25
0
def retrieve_contacts():
    db = contacts.open()
    fh = open('E:\data\python\contacts.txt', 'w')
    fh.write(db.export_vcards(db.keys()))
    fh.close()
    for contact in db.find(''):
        fields = ['first_name', 'last_name', 'mobile_number']
        find_values = [contact.find(field) for field in fields]
        values = [
            field_values[0].value if field_values else ''
            for field_values in find_values
        ]
        print contact.id,
        for value in values:
            print value,
        print
def select_contact(with_publish):
    db = contacts.open()

    clist = [ c for c
              in [ db[cid] for cid in db ]
              if (not c.is_group) and (c.find("email_address") != []) ]

    if with_publish:
        clist = [PublishContact()] + clist
    else:
        if clist == []:
            appuifw.note(u"No contacts to select", "error")
            return None

    chlist = [ unicode(c.title) for c in clist ]
    index = appuifw.popup_menu(chlist, u'Select contact')
    if index is None:
        return None

    chentry = clist[index]
    cmap = {}

    def get_value(name):
        fields = chentry.find(name)
        if len(fields) > 0:
            cmap[name] = fields[0].value
    
    fields = chentry.find("email_address")
    if len(fields) == 1:
        cmap["email_address"] = fields[0].value
    elif len(fields) > 1:
        chlist = [ unicode(f.value) for f in fields ]
        index = appuifw.popup_menu(chlist, u'Select address')
        if index is None:
            return None
        cmap["email_address"] = fields[index].value
    else:
        raise "assertion failure"

    get_value("first_name")
    get_value("last_name")
    get_value("first_name_reading")
    get_value("last_name_reading")
    get_value("second_name")

    return cmap
def script6():
    # open the database..
    db = contacts.open(u'test_database_3', 'n')

    # get available field types
    fieldtypes = db.field_types()

    # add new contacts
    contact1 = db.add_contact()
    contact1.add_field(contacts.first_name, u'Bill', u'Nickname')
    contact1.add_field(contacts.last_name, u'Mason')
    contact1.add_field(contacts.country, u'United States')
    contact1.commit()

    contact2 = db.add_contact()
    contact2.add_field(contacts.first_name, u'Julie')
    contact2.add_field(contacts.last_name, u'Richards')
    contact2.add_field(contacts.country, u'Canada')
    contact2.commit()

    print "search results for \'ichar\':"
    id_tuple = db.find(u'ichar')

    for id in id_tuple:
        print db[id]

    print ''

    print "search results for \'i\':"
    id_tuple = db.find(u'i')

    for id in id_tuple:
        print db[id]

    print ''

    # note that specifying the field types for the search
    # does not necessarily limit the search to only those
    # fields (because c++ api works like that..).
    print "search results for \'i\' in country-field':"
    id_tuple = db.find(u'i', (contacts.country, ))

    for id in id_tuple:
        print db[id]

    db.close()
def script5():
    # open the database..
    db = contacts.open(u'test_database_3', 'n')

    # get available field types
    fieldtypes = db.field_types()

    # add new contacts
    contact1 = db.add_contact()
    contact1.add_field(contacts.first_name, u'Bill', u'Nickname')
    contact1.add_field(contacts.last_name, u'Mason')
    contact1.commit()

    contact2 = db.add_contact()
    contact2.add_field(contacts.first_name, u'Julie')
    contact2.add_field(contacts.last_name, u'Richards')
    contact2.commit()

    id1 = contact1.entry_data()["uniqueid"]
    id2 = contact2.entry_data()["uniqueid"]

    # export "Bill" and "Julie"
    vcards = db.export_vcards((id1, id2))

    print u'***see bill and julie here***'
    for entry_id in db:
        print u'the contact:%s' % db[entry_id]
    print u''

    # delete "Bill"
    del db[id1]

    print u'***now bill has been deleted***'
    for entry_id in db:
        print u'the contact:%s' % db[entry_id]
    print u''

    # import "Bill" and "Julie"
    print db.import_vcards(vcards)

    print u'***now bill is imported back in vcard***'
    for entry_id in db:
        print u'the contact:%s' % db[entry_id]

    db.close()
Exemple #29
0
def backUpContact():
    db=contacts.open()
    names=[]
    numbers=[]
    appuifw.note(chn('名片提取中,请稍后...'),'info')
    for i in db:
        names.append(db[i].title)
        num=db[i].find("mobile_number")
        if  num:
            numbers.append(num[0].value)
        else :
            numbers.append(None)
    f=open("c:\\contact.txt","w")
    for i in range(len(names)):
        f.write(names[i].encode("utf8"))
        f.write(':')
        f.write(numbers[i])
        f.write("\n")
Exemple #30
0
def Num2Name(mobile_number):
	db = contacts.open()
	name = ''
	for id in db.keys():
		con = db[id]    # get the contact for each key
		nums = []
		for mobile_field in con.find('mobile_number'):   	# get the numbers associated with this contact
			nums += [mobile_field.value]
		for mobile_field in con.find('phone_number'):   	# get the numbers associated with this contact
			nums += [mobile_field.value]
			
		for num in nums		#iterate over all the number associated with a contact number
			if str(num).endswith(mobile_number) == 1 :
				if len(con.find('first_name')) >= 1:		# if first name set is >= 1 then first exists
					name += str(con.find('first_name')[0].value) +' ' 
				if len(con.find('last_name'))  >= 1:		# if last name set is >= 1 then last exists
					name += str(con.find('last_name')[0].value) + ' '
				print str(name)
def update_number():
	'''
	update the mobile number so that it start with +65
	'''
	db=contacts.open()
	print("-"*15)
	print(" searching for number not starting with +65")
	for entry_id in db:
		for field in db[entry_id]:
			#print ("%s:%s" % (field.label, field.value))
			if field.label == "Mobile":
				val=field.value[0]
				if val=='8' or val=='9' or val=='6':
					print db[entry_id]
					ret = update_me(field)
					if ret == -1:
						print 'exiting'
						return 0
	print("-"*15)
Exemple #32
0
def contactName2Number(contact):
	if len(contact) > 0 and contact[-1].isalpha() : # if given contact is name we need to convert it to number 
		contact = contact.lower().strip()
		db = contacts.open()
		num = ''
		for id in db.keys():
			name = '' 
			con = db[id]    # get the contact for each key
			if len(con.find('first_name')) >= 1:		# if first name set is >= 1 then first exists	
				name = str(con.find('first_name')[0].value) +' '
			if len(con.find('last_name')) >= 1:		# if first name set is >= 1 then first exists	
				name = name + str(con.find('last_name')[0].value) 
			if name.strip().lower() == contact :	
				for mobile_num in con.find('mobile_number'):   	# get the mobile numbers in each contact
					num = str(mobile_num.value)
				for mobile_num in con.find('phone_number'):   	# get the mobile numbers in each contact
					num = str(mobile_num.value)
		contact	= num 
	return contact.lstrip('+')[-10:]     # strip + sign and country code etc
Exemple #33
0
def script5():
    # open and empty the database, create if does not exist.
    db=contacts.open('test_database','n')
    
    # get available field types.
    fieldtypes=db.field_types()
    
    # add new contacts.
    contact1=db.add_contact()
    contact1.add_field('first_name',value='Bill',label='Nickname')
    contact1.add_field('last_name','Mason')
    contact1.commit()
    
    contact2=db.add_contact()
    contact2.add_field('first_name','Julie')
    contact2.add_field('last_name','Richards')
    contact2.add_field('mobile_number',value='76476547',location='work')
    contact2.add_field('mobile_number',value='76476548',location='home')
    contact2.commit()
    
    # export 'Bill' and 'Julie'.
    vcards=db.export_vcards((contact1.id,contact2.id))
    
    print '***see bill and julie here***'
    for entry_id in db:
        print 'the contact:%s'%db[entry_id]
    print ''
    
    # delete 'Bill'.
    del db[contact1.id]

    print '***now bill has been deleted***'
    for entry_id in db:
        print 'the contact:%s'%db[entry_id]
    print ''
    
    # import 'Bill' and 'Julie'.
    db.import_vcards(vcards)
    
    print '***now bill is imported back in vcard***'
    for entry_id in db:
        print 'the contact:%s'%db[entry_id]
Exemple #34
0
def script5():
    # open and empty the database, create if does not exist.
    db = contacts.open('test_database', 'n')

    # get available field types.
    fieldtypes = db.field_types()

    # add new contacts.
    contact1 = db.add_contact()
    contact1.add_field('first_name', value='Bill', label='Nickname')
    contact1.add_field('last_name', 'Mason')
    contact1.commit()

    contact2 = db.add_contact()
    contact2.add_field('first_name', 'Julie')
    contact2.add_field('last_name', 'Richards')
    contact2.add_field('mobile_number', value='76476547', location='work')
    contact2.add_field('mobile_number', value='76476548', location='home')
    contact2.commit()

    # export 'Bill' and 'Julie'.
    vcards = db.export_vcards((contact1.id, contact2.id))

    print '***see bill and julie here***'
    for entry_id in db:
        print 'the contact:%s' % db[entry_id]
    print ''

    # delete 'Bill'.
    del db[contact1.id]

    print '***now bill has been deleted***'
    for entry_id in db:
        print 'the contact:%s' % db[entry_id]
    print ''

    # import 'Bill' and 'Julie'.
    db.import_vcards(vcards)

    print '***now bill is imported back in vcard***'
    for entry_id in db:
        print 'the contact:%s' % db[entry_id]
Exemple #35
0
    def __init__(self):
        self.connected = False
        self.service = False
        self.useCanvas = True
        self.client = None

        self.inbox = inbox.Inbox(inbox.EInbox)
        self.sent = inbox.Inbox(inbox.ESent)
        self.contactDb = contacts.open()
        self.calendarDb = calendar.open()
        self.currentMessage = None
        self.__partialMessage = ""

        #FIXME: I shouldn't need this
        e32.ao_sleep(1)
        self.inbox.bind(self.newMessage)
        #telephone.call_state(self.handleCall)

        self.initUi()
        self.startService()
Exemple #36
0
    def __init__(self):
        self.connected = False
        self.service = False
        self.useCanvas = True
        self.client = None

        self.inbox = inbox.Inbox(inbox.EInbox)
        self.sent = inbox.Inbox(inbox.ESent)
        self.contactDb = contacts.open()
        self.calendarDb = calendar.open()
        self.currentMessage = None
        self.__partialMessage = ""

        #FIXME: I shouldn't need this
        e32.ao_sleep(1)
        self.inbox.bind(self.newMessage)
        #telephone.call_state(self.handleCall)

        self.initUi()
        self.startService()
Exemple #37
0
def Name2Num(search_name):
	search_name = search_name.lower()
	db = contacts.open()
	names = []
	name = ''
	for id in db.keys():
		name = ''
		con = db[id]    # get the contact for each key
		if len(con.find('first_name')) >= 1:		# if first name set is >= 1 then first exists	
			name = name + str(con.find('first_name')[0].value) +' '
		if len(con.find('last_name')) >= 1:		# if first name set is >= 1 then first exists	
			name = name + str(con.find('last_name')[0].value) + ' '
		if name.lower().find(search_name) > -1:	
			for mobile_num in con.find('mobile_number'):   	# get the mobile numbers in each contact
				name = name + '<' + str(mobile_num.value) + '>'	
			for mobile_num in con.find('phone_number'):   	# get the mobile numbers in each contact
				name = name + '<' + str(mobile_num.value) + '>'	
			names = names + [name]
	names.sort()
	print names
	print '------------------------'
Exemple #38
0
    def __init__(self):
        self.connected = False
        self.service = False
        self.useCanvas = True
        self.client = None
        self.port = PORT

        self.loadConfig()
        self.initUi()

        self.inbox = inbox.Inbox(inbox.EInbox)
        self.sent = inbox.Inbox(inbox.ESent)
        self.contactDb = contacts.open()
        self.calendarDb = calendar.open()
        self.currentMessage = None
        self.__partialMessage = ""

        self.inbox.bind(self.newMessage)
        # telephone.call_state(self.handleCall)

        self.startService()
Exemple #39
0
def getContactsData():
	db = contacts.open()
	all=[]
	for id in db:
		s60contact=db[id]
		first_name=""
		last_name=""
		phonenum=""
		try:
			first_name=s60contact.find(type="first_name")[0].value
		except:
			pass
		try:
			last_name=s60contact.find(type="last_name")[0].value
		except:
			pass
		try:
			phonenum=s60contact.find(type="mobile_number")[0].value
		except:
			pass
		all.append((first_name, last_name, phonenum))
	return pickle.dumps(all)
Exemple #40
0
def script7():
    # open and empty the database, create if does not exist.
    db = contacts.open('test_database', 'n')

    # add a contact.
    contact = db.add_contact()

    # delete all the default fields
    while len(contact):
        del contact[0]

    contact.add_field('first_name', value='Bill', label='Nickname')
    contact.add_field('last_name', value='Mason')
    contact.commit()

    # get first of contact's 'first_name' fields.
    field = contact.find('first_name')[0]
    field.value = 'Jack'  # change the name.

    print db[
        contact.
        id]  # autocommit is on (since the name has changed in the database).

    contact.begin()
    field.value = 'John'
    print db[
        contact.
        id]  # autocommit is off (since the name has not changed in the database).
    contact.commit()  # save the changes.

    print db[
        contact.
        id]  # commit() saved the changes (since the name has changed in the database).

    field.value = 'Henry'
    print db[
        contact.
        id]  # autocommit is on again (since the name is changed in the database).
Exemple #41
0
def build_cache(name_order):
    log(">> build_cache")
    # open database
    db = contacts.open()
    log("db.open")
    
    all_keys = db.keys()
    
    field1 = u''
    field2 = u''
    
    if name_order == "0":
        field1 = u'first_name'
        field2 = u'last_name'
    elif name_order == "1":
        field2 = u'first_name'
        field1 = u'last_name'
    
    log("name_order set")
    
    try:
        for i in all_keys:
            title = u''
            if db[i].find(field1):
                title = urllib.quote(unicode(db[i].find(field1)[0].value).lower())
            if db[i].find(field2):
                title += u' ' + urllib.quote(unicode(db[i].find(field2)[0].value).lower())
            
            tile = title.strip(u' ')
            #log("- list.append: " + title)
            if len(title) > 0:
                contacts_cache.append((i, title))
    except:
        log("- build_cache execpt: " + repr(sys.exc_info()))

    log("- build_cache done: " + str(len(contacts_cache)))
Exemple #42
0
def script4():
    # open and empty the database, create if does not exist.
    db=contacts.open('test_database','n')
    
    # add new contacts.
    contact1=db.add_contact()
    contact1.add_field('first_name',value='Bill',label='Nickname')
    contact1.add_field('last_name','Mason')
    contact1.commit()
    
    contact2=db.add_contact()
    contact2.add_field('first_name','Julie')
    contact2.add_field('last_name','Richards')
    contact2.add_field('mobile_number',value='76476547',location='work')
    contact2.add_field('mobile_number',value='76476548',location='home')
    contact2.commit()
        
    vcards=db.export_vcards((contact1.id,contact2.id))

    # print the vcard string (contains contact1 and contact2).
    print vcards

    # print contact1 as vcard.
    print contact1.as_vcard()
Exemple #43
0
def script4():
    # open and empty the database, create if does not exist.
    db = contacts.open('test_database', 'n')

    # add new contacts.
    contact1 = db.add_contact()
    contact1.add_field('first_name', value='Bill', label='Nickname')
    contact1.add_field('last_name', 'Mason')
    contact1.commit()

    contact2 = db.add_contact()
    contact2.add_field('first_name', 'Julie')
    contact2.add_field('last_name', 'Richards')
    contact2.add_field('mobile_number', value='76476547', location='work')
    contact2.add_field('mobile_number', value='76476548', location='home')
    contact2.commit()

    vcards = db.export_vcards((contact1.id, contact2.id))

    # print the vcard string (contains contact1 and contact2).
    print vcards

    # print contact1 as vcard.
    print contact1.as_vcard()
Exemple #44
0
def script10():
    # open the default database.
    db=contacts.open()

    # print information about all field types this database supports.
    print db.field_types()
    u"Delete Contacts",
    u"Find Contact",
    u"Edit Contact",
    u"Create Group",
    u"Delete Group",
    u"Add Member to Group",
    u"Date and Time",
    u"Add Calender events",
    u"Exit",
]

index = appuifw.selection_list(choices=L, search_field=1)

if index == 0:

    db = contacts.open()
    c = db.add_contact()
    fnam = appuifw.query(u"first_name:", "text")
    lnam = appuifw.query(u"last_name:", "text")
    no = appuifw.query(u"mobile_number:", "text")

    c.add_field("first_name", fnam)
    c.add_field("last_name", lnam)
    c.add_field("mobile_number", no)
    print "new contact\n" + fnam + "  " + lnam + "  " + no + "\n"
    c.commit()

elif index == 1:
    db = contacts.open()
    data = appuifw.query(u"Type contact to delete:", "text")
    l = db.find(data)
Exemple #46
0
def script10():
    # open the default database.
    db = contacts.open()

    # print information about all field types this database supports.
    print db.field_types()
Exemple #47
0
def script1():
    db = contacts.open()
    for id in db:
        print 'Contact:%s' % db[id]
    print 'number of entries:%i' % len(db)
#+------------------------------------------------------+
def TabSelChange(Index):
	DoSetTab(Index)

#+------------------------------------------------------+
# 		Default entries in boxes
#+------------------------------------------------------+
ScheduledListBox = appuifw.Listbox([(u'Empty', u'')], ScheduledListBoxObserve)	
HistoryListBox = appuifw.Listbox([(u'Empty', u'')])	

#+------------------------------------------------------+
#		Main 
#+------------------------------------------------------+
appuifw.app.title = u'SMSScheduler'

ContactsDB = contacts.open()

for i in ContactsDB.keys():
#	print i
	if ContactsDB[i].find('mobile_number')[0].value:
		ContactMobileNumber = ContactsDB[i].find('mobile_number')[0].value
#		print ContactMobileNumber
		if ContactMobileNumber and (len(ContactMobileNumber) > 0):
			ContactName = ContactsDB[i].find('first_name')[0].value
#			print ContactName
			if 0 == len(ContactName):
				Contacts.append((u'(unamed)', ContactMobileNumber))
			else:
				Contacts.append((ContactName, ContactMobileNumber))
			
Contacts.sort()
Exemple #49
0
 def setUp(self):
     self.db = contacts.open('c:test_db', 'n')
Exemple #50
0
def script1():
    db=contacts.open()
    for id in db:
        print 'Contact:%s'%db[id]
    print 'number of entries:%i'%len(db)
Exemple #51
0
import contacts
import time
import e32, e32socket, appuifw
import tempfile

db = contacts.open()

try:
    device = e32socket.bt_obex_discover()
except:
    pass
address = device[0]
channel = device[1][u"OBEX Object Push"]

out = ""
for key in db.keys():
    contact = db[key]
    out += contact.as_vcard()

out_file = tempfile.NamedTemporaryFile(mode="w")
out_file.write(out)
out_file.flush()

e32socket.bt_obex_send_file(address, channel, out_file.name)

e32socket.bt_obex_send_file(address, channel, u"e:\\tmp.txt")

appuifw.note(u"Picture sent", out_file.name)
out_file.close()

Exemple #52
0
    def tearDown(self):
        self.db = contacts.open('c:test_db', 'c')

        for id in self.db:
            del self.db[id]
        del self.db