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
Ane help will by apreciated
Yes, it's pretty simple. Quick example:
from win32com.client import Dispatch
session = Dispatch('Lotus.NotesSession')
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()
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
doc = docs.getFirstDocument()
doc = docs.getNextDocument(doc)
Then you can write much cleaner code, like this:
for doc in iterateDocuments(view):
Similarly you can write iterator functions for traversing databases,
ACL entries, etc.
I also find these two defnitions useful:
def get(doc, attr):
def get1(doc, attr):
return get(doc, attr)
because it's a lot easier to write:
user_name = get1(user_doc, 'FullName')
user_name = user_doc.getItemValue('FullName')
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.