Jppy: AddressDB support in python-jppy

Nicholas Piper nick at nickpiper.co.uk
Tue Feb 13 12:06:10 GMT 2007


I added AddressDB support to the library. No GUI (yet? - please ask if
it'd be useful.)

It's in trunk r180.

Here's a quick example:

Import jppy as normal:

In [1]:import jppy

If you use the default provider, which is jpilot talking to a Palm TX
with DateBk6 features, you can see you get a datebk6.Contact class
used for your Contact records:

In [2]:jppy.setProvider('jpilot_tx',dateBkFeatures=True)

In [3]:print jppy.Contact().__class__
<class 'jppy.datebk6.Contact'>

If you switch provider to plain jpilot, you now get an Address class instead:

In [4]:jppy.setProvider('jpilot',dateBkFeatures=False)

In [5]:print jppy.Contact().__class__
<type 'jppy._jpilot.__jpilot.Address'>

Open addressBook as normal:

In [6]:ab = jppy.addressBook()

In [7]:a_record = ab.records()[17]

In [8]:print a_record
<jppy._jpilot.__jpilot.Address 'Mark' 'Brown' d:0 m:0 b:0 s:0 a:0 cat:2 type:normal uid=747391>

You obviously get less keys than with jpilot_tx. I kept the '1' on the
address details, to make it easier to mix-and-match ContactsDB and
AddressDB items...

In [9]:print a_record.keys()
['lastname', 'firstname', 'company', 'title', 'phone1', 'phone2', 'phone3', 'phone4', 'phone5', 'address1', 'city1', 'state1', 'zip1', 'country1', 'cus tom1', 'custom2', 'custom3', 'custom4', 'note', 'currentphone', 'showphone']

Make a new Contact in the normal way (but of course, this is backed by
jppy._jpilot.__jpilot.Address rather than
jppy._jpilot.__jpilot.Contact) because of our setProvider() before:

In [10]:new = jppy.Contact()

In [11]:new['firstname'] = "John"

In [12]:new['lastname'] = "WithLongLastName"

In [13]:print new
<jppy._jpilot.__jpilot.Address 'John' 'WithLongLastName' d:0 m:0 b:0 s:0 a:0 cat:0 type:unknown uid=0>

Add it to the database in the normal way:

In [14]:ab.save(new)
Out[14]:<jppy._jpilot.__jpilot.Address 'John' 'WithLongLastName' d:0 m:0 b:0 s:0 a:0 cat:0 type:unknown uid=1>

And you get the normal vcard creation feature too:

In [15]:new.vcard()
Out[15]:'BEGIN:VCARD\r\nVERSION:2.1\r\nN:WithLongLastName;John\r\nFN:John WithLongLastName\r\nORG:\r\nADR:\r\nEND:VCARD\r\n\r\n'

Hope that's useful for someone, please let me know if it is.

Obviously, you _can't use both_, as jpilot MUST be set to sync with
AddressDB (as jpilot comes shipped, it does that), *OR* turn off
AddressDB syncing and add the jppy ContactsDB jpilot plugin.

 Nick

-- 
Nick Piper, Developer, LogicaCMG           http://www.nickpiper.co.uk/
GPG Encrypted mail welcome!                             1024D/3ED8B27F
Choose life. Be Vegan :-) Please reduce needless cruelty & suffering !




More information about the Jppy mailing list