Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python and Lotus Notes

Reply
Thread Tools

Python and Lotus Notes

 
 
=?ISO-8859-2?Q?Grzegorz_=A6lusarek?=
Guest
Posts: n/a
 
      11-02-2005
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
 
Reply With Quote
 
 
 
 
Graham Fawcett
Guest
Posts: n/a
 
      11-02-2005

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

 
Reply With Quote
 
 
 
 
=?UTF-8?B?R3J6ZWdvcnogxZpsdXNhcmVr?=
Guest
Posts: n/a
 
      11-03-2005
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
 
Reply With Quote
 
Marco Aschwanden
Guest
Posts: n/a
 
      11-04-2005

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

 
Reply With Quote
 
Graham Fawcett
Guest
Posts: n/a
 
      11-04-2005
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

 
Reply With Quote
 
thakadu
Guest
Posts: n/a
 
      11-04-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C# 2.0 (Lotus Notes 6 & 7) Create mail document in draft folder for Lotus Notes SteveM ASP .Net 5 08-28-2007 04:16 PM
Python and Lotus Notes bisj Python 0 11-13-2005 12:54 PM
Access lotus notes using Python Sateesh Python 13 05-24-2005 11:23 PM
Accessing email from Notes-mail-server without Lotus Notes installed Bjorn Jensen Perl 0 03-22-2005 01:44 PM
Virus Alert - ScanMail for Lotus Notes --> Delivery(python-list@python.org) timanfaya/TSM@tsm.es Python 0 05-18-2004 07:48 AM



Advertisments