Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS 

export contacts as cvs

import sysinfo
import e32
import os
import os.path
import re
import time
import urllib
import contacts
import codecs

CODEC='utf-16'
CVSFILENAME='E:\\contactsdb.cvs'

def getFieldtypenames():
    "Return the list of fields"
    dic = contacts.fieldtypemap
    num = [[v,k] for k,v in dic.items()]
    num.sort()
    if num[0][0]==0 and num[0][1]=='none':
        del num[0]
    return [v for k,v in num]


def exportContacts(filename):
    messages = []

    f = None
    try:
        f = codecs.open(filename,'w+',CODEC)
    except:
        print 'error creation file'

    if not f:
        return -1

    fields = getFieldtypenames()
    fieldformat = u''.join(['%('+v+')s,' for v in fields ])[0:-1]
    fieldformat+= '\n'
    fieldname = u''.join([''+v+',' for v in fields ])[0:-1]
    f.write("%s\n"%fieldname)
    
    try:
        db = contacts.open()
        idlist = db.keys()

        for id in idlist:
            newdict = dict([[k,''] for k in fields])
            contact = db[id]
            for field in contact:
                newdict[field.type]=field.value
            f.write(fieldformat%newdict)
    except:
        pass
    f.close()
        

def main():
   exportContacts(CVSFILENAME)


if __name__=='__main__':
    main()

Popup dialog for phonebook number

A minimal example to let you choose from you mobile phonebook.
import contacts, appuifw
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) # first mobile
  else:
    numbers.append(None)

i = appuifw.selection_list(names)
print 'number =', numbers[i]

make a phone call

py_s60 1.1.3 provide a module to make call
import telephone
telephone.dial('017337330') # so easy

You can hang up by... guess it...
telephone.hang_up()

You can combine this with the contacts module to search and dial
import contacts, telephone
name = 'korakot'
cont = contacts.open().find(name)[0]
number = cont.find('mobile_number')[0].value
telephone.dial(number)

Using phonebook(contact) database

Now you can access and modify your mobile phone
contact database. Add new person, phone, email, etc.
Here's a short example
import contacts
db = contacts.open()

all_ids = db.keys() # [159, 161, 273, ...]
c = db[159]  # first contact
found = db.find('jim')  # search in name, email, etc.
jim = found[0]  # first one found

jim_id = jim.id  # 819
mobile = jim.find('mobile_number')[0].value  # first only
firstname = jim.find('first_name')[0].value
# other fields: email_address, url, company_name, job_title, 
# phone_number, fax_number, note, etc.

# to add new contact
newc = db.add_contact()
newc.add_field('first_name', 'Korakot')
newc.add_field('mobile_number', '017337330')
newc.commit()

Group infomation is missing, though.

SQL in python series 60

DBMS is the native format for database on symbian platform.
Python for series 60 provide a 'e32db' module to access dbms.
import e32db
db = e32db.Dbms()
dbv = e32db.Db_view()
db.open(u'C:\\System\\Data\\Contacts.cdb ')  # open database file

# search and retrieve from a row
def select_row(query):
  dbv.prepare(db, unicode(query))
  dbv.first_line()
  dbv.get_line()
  result = []
  for i in range(dbv.col_count()):
    result.append(dbv.col(i+1))
  return result

# search and retrieve from a column
def select_col(query):
  dbv.prepare(db, unicode(query))
  dbv.first_line()
  result = []
  for i in range(dbv.count_line()):
    dbv.get_line()
    result.append(dbv.col(1))
    dbv.next_line()
  return result

# now it's quite easy to query anything, for example
# get the id of my friend "Jakapong"
id, = select_row("select parent_cmid from identitytable where cm_firstname='Jakapong' ")


I show more example here at nokia forum.
http://discussion.forum.nokia.com/forum/showthread.php?threadid=55674
« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS