<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: phonebook code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Mon, 06 Oct 2008 14:26:13 GMT</pubDate>
    <description>DZone Snippets: phonebook code</description>
    <item>
      <title>export contacts as cvs</title>
      <link>http://snippets.dzone.com/posts/show/695</link>
      <description>&lt;code&gt;&lt;br /&gt;import sysinfo&lt;br /&gt;import e32&lt;br /&gt;import os&lt;br /&gt;import os.path&lt;br /&gt;import re&lt;br /&gt;import time&lt;br /&gt;import urllib&lt;br /&gt;import contacts&lt;br /&gt;import codecs&lt;br /&gt;&lt;br /&gt;CODEC='utf-16'&lt;br /&gt;CVSFILENAME='E:\\contactsdb.cvs'&lt;br /&gt;&lt;br /&gt;def getFieldtypenames():&lt;br /&gt;    "Return the list of fields"&lt;br /&gt;    dic = contacts.fieldtypemap&lt;br /&gt;    num = [[v,k] for k,v in dic.items()]&lt;br /&gt;    num.sort()&lt;br /&gt;    if num[0][0]==0 and num[0][1]=='none':&lt;br /&gt;        del num[0]&lt;br /&gt;    return [v for k,v in num]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;def exportContacts(filename):&lt;br /&gt;    messages = []&lt;br /&gt;&lt;br /&gt;    f = None&lt;br /&gt;    try:&lt;br /&gt;        f = codecs.open(filename,'w+',CODEC)&lt;br /&gt;    except:&lt;br /&gt;        print 'error creation file'&lt;br /&gt;&lt;br /&gt;    if not f:&lt;br /&gt;        return -1&lt;br /&gt;&lt;br /&gt;    fields = getFieldtypenames()&lt;br /&gt;    fieldformat = u''.join(['%('+v+')s,' for v in fields ])[0:-1]&lt;br /&gt;    fieldformat+= '\n'&lt;br /&gt;    fieldname = u''.join([''+v+',' for v in fields ])[0:-1]&lt;br /&gt;    f.write("%s\n"%fieldname)&lt;br /&gt;    &lt;br /&gt;    try:&lt;br /&gt;        db = contacts.open()&lt;br /&gt;        idlist = db.keys()&lt;br /&gt;&lt;br /&gt;        for id in idlist:&lt;br /&gt;            newdict = dict([[k,''] for k in fields])&lt;br /&gt;            contact = db[id]&lt;br /&gt;            for field in contact:&lt;br /&gt;                newdict[field.type]=field.value&lt;br /&gt;            f.write(fieldformat%newdict)&lt;br /&gt;    except:&lt;br /&gt;        pass&lt;br /&gt;    f.close()&lt;br /&gt;        &lt;br /&gt;&lt;br /&gt;def main():&lt;br /&gt;   exportContacts(CVSFILENAME)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;if __name__=='__main__':&lt;br /&gt;    main()&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 10 Sep 2005 03:35:15 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/695</guid>
      <author>agathe ()</author>
    </item>
    <item>
      <title>Popup dialog for phonebook number</title>
      <link>http://snippets.dzone.com/posts/show/482</link>
      <description>A minimal example to let you choose from you mobile phonebook.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import contacts, appuifw&lt;br /&gt;db = contacts.open()&lt;br /&gt;names = []&lt;br /&gt;numbers = []&lt;br /&gt;for i in db:&lt;br /&gt;  names.append(db[i].title)&lt;br /&gt;  num = db[i].find('mobile_number')&lt;br /&gt;  if num:&lt;br /&gt;    numbers.append(num[0].value) # first mobile&lt;br /&gt;  else:&lt;br /&gt;    numbers.append(None)&lt;br /&gt;&lt;br /&gt;i = appuifw.selection_list(names)&lt;br /&gt;print 'number =', numbers[i]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 18 Jul 2005 19:47:07 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/482</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>make a phone call</title>
      <link>http://snippets.dzone.com/posts/show/395</link>
      <description>py_s60 1.1.3 provide a module to make call&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import telephone&lt;br /&gt;telephone.dial('017337330') # so easy&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;You can hang up by... guess it...&lt;code&gt;telephone.hang_up()&lt;/code&gt;&lt;br /&gt;You can combine this with the contacts module to search and dial&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import contacts, telephone&lt;br /&gt;name = 'korakot'&lt;br /&gt;cont = contacts.open().find(name)[0]&lt;br /&gt;number = cont.find('mobile_number')[0].value&lt;br /&gt;telephone.dial(number)&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 19 Jun 2005 14:58:38 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/395</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>Using phonebook(contact) database</title>
      <link>http://snippets.dzone.com/posts/show/379</link>
      <description>Now you can access and modify your mobile phone&lt;br /&gt;contact database. Add new person, phone, email, etc.&lt;br /&gt;Here's a short example&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import contacts&lt;br /&gt;db = contacts.open()&lt;br /&gt;&lt;br /&gt;all_ids = db.keys() # [159, 161, 273, ...]&lt;br /&gt;c = db[159]  # first contact&lt;br /&gt;found = db.find('jim')  # search in name, email, etc.&lt;br /&gt;jim = found[0]  # first one found&lt;br /&gt;&lt;br /&gt;jim_id = jim.id  # 819&lt;br /&gt;mobile = jim.find('mobile_number')[0].value  # first only&lt;br /&gt;firstname = jim.find('first_name')[0].value&lt;br /&gt;# other fields: email_address, url, company_name, job_title, &lt;br /&gt;# phone_number, fax_number, note, etc.&lt;br /&gt;&lt;br /&gt;# to add new contact&lt;br /&gt;newc = db.add_contact()&lt;br /&gt;newc.add_field('first_name', 'Korakot')&lt;br /&gt;newc.add_field('mobile_number', '017337330')&lt;br /&gt;newc.commit()&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Group infomation is missing, though.</description>
      <pubDate>Thu, 09 Jun 2005 15:34:42 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/379</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>SQL in python series 60</title>
      <link>http://snippets.dzone.com/posts/show/127</link>
      <description>DBMS is the native format for database on symbian platform.&lt;br /&gt;Python for series 60 provide a 'e32db' module to access dbms.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import e32db&lt;br /&gt;db = e32db.Dbms()&lt;br /&gt;dbv = e32db.Db_view()&lt;br /&gt;db.open(u'C:\\System\\Data\\Contacts.cdb ')  # open database file&lt;br /&gt;&lt;br /&gt;# search and retrieve from a row&lt;br /&gt;def select_row(query):&lt;br /&gt;  dbv.prepare(db, unicode(query))&lt;br /&gt;  dbv.first_line()&lt;br /&gt;  dbv.get_line()&lt;br /&gt;  result = []&lt;br /&gt;  for i in range(dbv.col_count()):&lt;br /&gt;    result.append(dbv.col(i+1))&lt;br /&gt;  return result&lt;br /&gt;&lt;br /&gt;# search and retrieve from a column&lt;br /&gt;def select_col(query):&lt;br /&gt;  dbv.prepare(db, unicode(query))&lt;br /&gt;  dbv.first_line()&lt;br /&gt;  result = []&lt;br /&gt;  for i in range(dbv.count_line()):&lt;br /&gt;    dbv.get_line()&lt;br /&gt;    result.append(dbv.col(1))&lt;br /&gt;    dbv.next_line()&lt;br /&gt;  return result&lt;br /&gt;&lt;br /&gt;# now it's quite easy to query anything, for example&lt;br /&gt;# get the id of my friend "Jakapong"&lt;br /&gt;id, = select_row("select parent_cmid from identitytable where cm_firstname='Jakapong' ")&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;I show more example here at nokia forum.&lt;br /&gt;http://discussion.forum.nokia.com/forum/showthread.php?threadid=55674&lt;br /&gt;</description>
      <pubDate>Mon, 11 Apr 2005 04:26:59 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/127</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
