Python and Lotus Notes

Discussion in 'Python' started by =?ISO-8859-2?Q?Grzegorz_=A6lusarek?=, Nov 2, 2005.

  1. Hello everyone. I have to get data from Lotus Notes and i curious is it
    possible doing it with Python. I heard that Lotus Notes using COM, so
    the Python does so maybe it can be done? Anyone have any experiences
    doing that?
    Ane help will by apreciated
    Gregor
     
    =?ISO-8859-2?Q?Grzegorz_=A6lusarek?=, Nov 2, 2005
    #1
    1. Advertising

  2. Grzegorz Slusarek wrote:
    > Hello everyone. I have to get data from Lotus Notes and i curious is it
    > possible doing it with Python. I heard that Lotus Notes using COM, so
    > the Python does so maybe it can be done? Anyone have any experiences
    > doing that?
    > Ane help will by apreciated


    Yes, it's pretty simple. Quick example:

    from win32com.client import Dispatch
    session = Dispatch('Lotus.NotesSession')
    session.Initialize(MY_NOTES_PASSWORD)

    db = session.getDatabase(SERVER_NAME, DB_NAME)
    ...

    The LotusScript reference guide is almost completely applicable to
    Notes via COM.

    It can be useful to define some helper functions to make working with
    Notes a bit easier. For example, this is the (very clunky) way to
    iterate all documents in a Notes database, without helper code:

    view = db.getView('Important Docs')
    doc = db.getFirstDocument()
    while doc:
    do_something_with(doc)
    doc = view.getNextDocument(doc)

    You probably recognize the pattern from any LotusScript you've written.
    (It sure is easy to forget that last line...)

    But Python gives you far better control structures, like generators.
    It's worthwhile to define a few helper functions like this, in a common
    module:

    def iterateDocuments(docs):
    doc = docs.getFirstDocument()
    while doc:
    yield doc
    doc = docs.getNextDocument(doc)

    Then you can write much cleaner code, like this:

    for doc in iterateDocuments(view):
    do_something_with(doc)

    Similarly you can write iterator functions for traversing databases,
    ACL entries, etc.

    I also find these two defnitions useful:

    def get(doc, attr):
    return doc.getItemValue(attr)

    def get1(doc, attr):
    return get(doc, attr)[0]

    because it's a lot easier to write:

    user_name = get1(user_doc, 'FullName')

    than:

    user_name = user_doc.getItemValue('FullName')[0]

    Note that the attribute-access style that LotusScript allows, e.g.
    "user_doc.FullName(0)" does not work in Python/COM, hence you'll need
    getItemValue(), replaceItemValue(), etc.. You could write a wrapper for
    the NotesDocument class that would give you attributes like this.
    Personally, I find that to be more trouble than it's worth, but your
    needs be very different.

    Last warning: once you've tried using Python and COM, you'll scream
    whenever you have to write LotusScript, and you'll wish like crazy that
    Notes/Domino supported Python as a native scripting language. :)
    Jython kind of works, but I never got it happily running for
    server-side code, alas.

    Graham
     
    Graham Fawcett, Nov 2, 2005
    #2
    1. Advertising

  3. thank you Graham
    Now I know how to get it thru
    And i have last question is it possible send mail from Lotus via
    Python/COM?
    Once Again Thanks
     
    =?UTF-8?B?R3J6ZWdvcnogxZpsdXNhcmVr?=, Nov 3, 2005
    #3
  4. The second line of your code is already a show stopper in my case:

    from win32com.client import Dispatch
    session = Dispatch('Lotus.NotesSession')
    session.Initialize('my_secret_passwort')

    When started, ends:

    File
    "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
    line 310, in RunScript
    exec codeObject in __main__.__dict__
    File "C:\temp\notes_init.py", line 3, in ?
    session.Initialize('my_secret_passwort')
    File "c:\Python24\lib\site-packages\win32com\client\dynamic.py", line
    489, in __getattr__
    raise AttributeError, "%s.%s" % (self._username_, attr)
    AttributeError: Lotus.NotesSession.Initialize

    It worked before though with Version 5.x of Notes. In Notes Version 6.X
    they introduced the session.Initialize() - that was the point, when I
    couldn't create an instance anymore. I found no hint on the net... Do you
    have any idea what is going wrong here?

    Regards,
    Marco
     
    Marco Aschwanden, Nov 4, 2005
    #4
  5. Marco Aschwanden wrote:
    > The second line of your code is already a show stopper in my case:
    >
    > from win32com.client import Dispatch
    > session = Dispatch('Lotus.NotesSession')
    > session.Initialize('my_secret_passwort')
    >
    > When started, ends:
    > [snip]
    > AttributeError: Lotus.NotesSession.Initialize
    >
    > It worked before though with Version 5.x of Notes. In Notes Version 6.X
    > they introduced the session.Initialize() - that was the point, when I
    > couldn't create an instance anymore. I found no hint on the net... Do you
    > have any idea what is going wrong here?


    I'm using 6.x here, so that's not the problem.

    Is there any chance you have an old gen_py file in your path? E.g.,
    does re-running the PythonWin "makepy" utility again make a difference?
    Just a thought, but something might be "hard-coded" to your earlier 5.x
    COM interface, and gen_py would be a likely suspect.

    Also, If you have another language that you can use to do COM, e.g.
    Visual Basic (in any of the MS Office apps, or in Visual Studio),
    verify that you can create a Lotus.NotesSession using those
    environments as well. It might be a lower-level (non-Python-related)
    problem.

    Graham
     
    Graham Fawcett, Nov 4, 2005
    #5
  6. =?ISO-8859-2?Q?Grzegorz_=A6lusarek?=

    thakadu Guest

    I have had success with jython using the notes.jar classes, for
    example:

    import lotus.domino
    import java.io
    import java.net
    import java.lang
    import java.util

    lotus.notes.NotesThread.sinitThread()
    S = lotus.notes.Session.newInstance();
    db=S.getDatabase("server/domain","domlog.nsf")
    agent=db.getAgent("DeleteOldDocs")
    for x in range(50):
    print x
    result=agent.runOnServer()
    print "res %d" % result
     
    thakadu, Nov 4, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bjorn Jensen
    Replies:
    0
    Views:
    1,199
    Bjorn Jensen
    Mar 22, 2005
  2. timanfaya/
    Replies:
    0
    Views:
    458
    timanfaya/
    May 18, 2004
  3. Sateesh

    Access lotus notes using Python

    Sateesh, May 23, 2005, in forum: Python
    Replies:
    13
    Views:
    5,307
    Dan Poirier
    May 25, 2005
  4. bisj

    Python and Lotus Notes

    bisj, Nov 13, 2005, in forum: Python
    Replies:
    0
    Views:
    398
  5. SteveM
    Replies:
    5
    Views:
    1,584
    Mark Rae [MVP]
    Aug 28, 2007
Loading...

Share This Page