Skip to content

Instantly share code, notes, and snippets.

@tts
Forked from domoritz/wos.php
Last active December 28, 2015 05:29
Show Gist options
  • Save tts/7450162 to your computer and use it in GitHub Desktop.
Save tts/7450162 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# tts: The WSDL URLs have changed, and some minor changes in qparams and rparams
from suds.client import Client
from suds.transport.http import HttpTransport
import urllib2
class HTTPSudsPreprocessor(urllib2.BaseHandler):
def __init__(self, SID):
self.SID = SID
def http_request(self, req):
req.add_header('cookie', 'SID="'+self.SID+'"')
return req
https_request = http_request
class WokmwsSoapClient():
"""
main steps you have to do:
soap = WokmwsSoapClient()
results = soap.search(...)
"""
def __init__(self):
self.url = self.client = {}
self.SID = ''
self.url['auth'] = 'http://search.webofknowledge.com/esti/wokmws/ws/WOKMWSAuthenticate?wsdl'
self.url['search'] = 'http://search.webofknowledge.com/esti/wokmws/ws/WokSearchLite?wsdl'
self.prepare()
def __del__(self):
self.close()
def prepare(self):
"""does all the initialization we need for a request"""
self.initAuthClient()
self.authenticate()
self.initSearchClient()
def initAuthClient(self):
self.client['auth'] = Client(self.url['auth'])
def initSearchClient(self):
http = HttpTransport()
opener = urllib2.build_opener(HTTPSudsPreprocessor(self.SID))
http.urlopener = opener
self.client['search'] = Client(self.url['search'], transport = http)
def authenticate(self):
self.SID = self.client['auth'].service.authenticate()
def close(self):
self.client['auth'].service.closeSession()
def search(self, query):
qparams = {
'databaseId' : 'WOS',
'userQuery' : query,
'queryLanguage' : 'en',
'editions' : [{
'collection' : 'WOS',
'edition' : 'SCI',
},{
'collection' : 'WOS',
'edition' : 'SSCI',
}]
}
rparams = {
'count' : 5, # 1-100
'firstRecord' : 1,
}
return self.client['search'].service.search(qparams, rparams)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment