[python-win32]  Re: WABAccess help ... 
Clinton Lee Taylor wrote:
> Greetings ...
>
> Take two ... This time I think I found something a little better ...
> http://sourceforge.net/projects/wabaccess/
>
> Another LGPL com lib to access Windows Address Book ... But this one
> seems to work with Python ...
>
> Okay, so I'm asking again, if anybody (maybe Roger again ... ) Could
> help with a basic working example of how to get just something listing
> out of the WAB ...
>
> Spend a whole night, with the following code, but can only put stuff
> into the WAB, not get a list of e-mail address ...
>
>
> import win32com.client
>
> objSession = win32com.client.gencache.EnsureDispatch("WABAccess.Session")
>
> print objSession
>
> objSession.Open(False)
>
> if objSession.Identities.LastIdentity ==
> "{00000000-0000-0000-0000-000000000000}":
>    print "No Identity Selected"
> else:
>    print "The Identity " +
> objSession.Identities(objSession.Identities.LastIdentity).Name + " is
> selected"
>
> print objSession.Identities.DefaultIdentity
> print objSession.Identities.Count
>
> print objSession.Containers.Count
>
> objContainer = objSession.Containers(1)
>
> objMyContact=objContainer.Elements.NewContact( False, "Clinton Taylor" )
>
> # FixMe, throught all the constant things would be import somehow ...
> PR_EMAIL_ADDRESS = 0x3003001F
> PR_BUSINESS_HOME_PAGE = 0x3A51001F
> PR_COMPANY_NAME = 0x3A16001F
> PR_BUSINESS_ADDRESS_CITY = 0x3A27001F


These show up in win32com.client.constants, eg
>>> win32com.client.constants.wabPR_EMAIL_ADDRESS
805503007


> City = "Paris"
> # objCityProperty = objMyContact.Properties.Add(
> wabPR_BUSINESS_ADDRESS_CITY, City )
> objCityProperty = objMyContact.Properties.Add( PR_BUSINESS_ADDRESS_CITY, 
> City )
>
> # Adding an email address
> objMyContact.Properties.Add (PR_EMAIL_ADDRESS, "iwzx.rhwas@mysociety.com")
> # Adding the Web page property
> objMyContact.Properties.Add (PR_BUSINESS_HOME_PAGE, 
> "http://www.mysociety.com")
> # Adding the company name property
> objProperty = objMyContact.Properties.Add(PR_COMPANY_NAME, "")
> # Changing the company name property
> objProperty.Value = "My Society Name"
>
> objMyContact.ShowDetails
>
> objMyRecipients = objSession.ShowAddress()
>
> objSession.Refresh
>
> objSession.Close
> print "Done."

You're missing some parens from the ShowDetails and Refresh lines.
With those in place, this code works for me (at least on XP, haven't
tried it on Vista yet)

            Roger

_______________________________________________
python-win32 mailing list
kpitck-aew45@python.org
http://mail.python.org/mailman/listinfo/python-win32


