Difference between revisions of "Python client - OpenKM 5.1"

From OpenKM Documentation
Jump to: navigation, search
(Download document)
(Download document)
Line 100: Line 100:
  
 
import warnings, base64
 
import warnings, base64
warnings.simplefilter('ignore',DeprecationWarning)
+
warnings.simplefilter('ignore', DeprecationWarning)
  
 
from SOAPpy import WSDL
 
from SOAPpy import WSDL

Revision as of 11:27, 30 September 2010

These sample code is using the SOAPpy library. If you are in a Debian based distro you can install it this way:

$ sudo aptitude install python-soappy

More info about Python and webservices at:

Remote method info

from SOAPpy import WSDL

# Register WSDL
sAuth = WSDL.Proxy('http://localhost:8080/OpenKM/OKMAuth?wsdl')

print sAuth.methods.keys()
print sAuth.soapproxy

callInfo = sAuth.methods['login']

print callInfo.inparams[0].name
print callInfo.inparams[0].type

print callInfo.inparams[1].name
print callInfo.inparams[1].type

Authentication

from SOAPpy import WSDL

# Register WSDL
sAuth = WSDL.Proxy('http://localhost:8080/OpenKM/OKMAuth?wsdl')

# Login
token = sAuth.login(arg0='okmAdmin', arg1='admin')
print 'Token: '+token

# Logout
sAuth.logout(arg0=token)

Create document

from SOAPpy import WSDL
 
# Register WSDL
sAuth = WSDL.Proxy('http://localhost:8080/OpenKM/OKMAuth?wsdl')
sDocument = WSDL.Proxy('http://localhost:8080/OpenKM/OKMDocument?wsdl')
 
# Login
token = sAuth.login(arg0='okmAdmin', arg1='admin')
print 'Token: '+token
 
# Create document
newDoc = sDocument.create(arg0=token, arg1={'path':'/okm:root/hosts_1.txt', 'mimeType': None,
    'actualVersion': None, 'author': None, 'checkedOut': False,
    'created': None, 'language': None,
    'lastModified': None, 'lockInfo': None, 'locked': False,
    'permissions': 0, 'size': 0, 'subscribed': False, 'uuid': None,
    'convertibleToPdf': False, 'convertibleToSwf': False,
    'compactable': False, 'training': False}, arg2='esto es una prueba')
print newDoc 
 
# Logout
sAuth.logout(arg0=token)

Perform search

from SOAPpy import WSDL

# Register WSDL
sAuth = WSDL.Proxy('http://localhost:8080/OpenKM/OKMAuth?wsdl')
sSearch = WSDL.Proxy('http://localhost:8080/OpenKM/OKMSearch?wsdl')

# Login
token = sAuth.login(arg0='okmAdmin', arg1='admin')
print 'Token: '+token

# Search
queryResultArray = sSearch.findByContent(arg0=token, arg1='grial')

for queryResult in queryResultArray['value']:
  print queryResult['document']['path']

# Logout
sAuth.logout(arg0=token)

Download document

#!/usr/bin/python
# -*- coding: utf-8 -*-

import warnings, base64
warnings.simplefilter('ignore', DeprecationWarning)

from SOAPpy import WSDL
 
# Register WSDL
sAuth = WSDL.Proxy('http://localhost:8080/OpenKM/OKMAuth?wsdl')
sDocument = WSDL.Proxy('http://localhost:8080/OpenKM/OKMDocument?wsdl')
 
# Login
token = sAuth.login(user='okmAdmin', password='admin')
print 'Token: '+token

docPath = u'/okm:root/path/to/document.pdf'
content = sDocument.getContent(token=token, docPath=docPath, checkout=False);
file = open('document.pdf', 'wb');
file.write(base64.decodestring(content));
file.close();

# Logout
sAuth.logout(token=token)