|
|
![]() Python Script SnippetThis code snippet references the ABAService Web Service only. To reference the ABAExpress Web Service,change the result_xml=_SOAP_post values to https://www.lyonsreg.com/webservices/abaexpress/...
#!usr/bin/env/python
"""
Sample Python script using Lyons ABA web service methods
tested on Python 2.4.
ABA Web Service Documentation
https://www.lyonsreg.com/products/getprimarybankfullxml.asp
import httplib
import urllib
import xml.dom.minidom
#-------SETTINGS-------
HOST = 'www.lyonsreg.com'
URL = '/webservices/aba/ABAService.asmx'
httplib.HTTPConnection.debuglevel = 0
#----------------------
def _str_to_bool(val):
"""Convenience function"""
val=str(val).lower()
assert val in ['false','true']
return bool(['false','true'].index(val))
def _SOAP_post(SOAPAction,xml):
"""Handles making the SOAP request"""
h = httplib.HTTPConnection(HOST)
headers={
'Host':HOST,
'Content-Type':'text/xml; charset=utf-8',
'Content-Length':len(xml),
'SOAPAction':'"%s"' % SOAPAction,
}
h.request ('POST', URL, body=xml,headers=headers)
r = h.getresponse()
d = r.read()
if r.status!=200:
raise ValueError('Error connecting: %s, %s' % (r.status, r.reason))
return d
def _logon(companyID,username,password):
"""First call logon to get your token"""
in_xml="""\
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Logon xmlns="http://www.lyonsreg.com/WebService/ABAService">
<companyID>%s</companyID>
<userName>%s</userName>
<password>%s</password>
</Logon>
</soap:Body>
</soap:Envelope>""" % (companyID,username,password)
result_xml=_SOAP_post("http://www.lyonsreg.com/WebService/ABAService/Logon",in_xml)
doc=xml.dom.minidom.parseString(result_xml)
response=doc.getElementsByTagName('LogonResult')[0].firstChild.data
return response
def logoff(token):
"""I guess call this when you're done"""
in_xml="""\
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Logoff xmlns="http://www.lyonsreg.com/WebService/ABAService">
<token>%s</token>
</Logoff>
</soap:Body>
</soap:Envelope>""" % token
result_xml=_SOAP_post("http://www.lyonsreg.com/WebService/ABAService/Logoff",in_xml)
return True
def _required_logon(token):
"""Use this to know if you need to login again"""
in_xml="""\
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<RequiredLogon xmlns="http://www.lyonsreg.com/WebService/ABAService">
<token>%s</token>
</RequiredLogon>
</soap:Body>
</soap:Envelope>""" % token
result_xml=_SOAP_post("http://www.lyonsreg.com/WebService/ABAService/RequiredLogon",in_xml)
doc=xml.dom.minidom.parseString(result_xml)
response=doc.getElementsByTagName('RequiredLogonResult')[0].firstChild.data
return _str_to_bool(response)
def bool_verify_ABA(aba,companyID,username,password):
"""Lookup ABA number on Lyons Server and return if found.
Note: This function handles logging in for you, if it finds you need to."""
global TOKEN
if (not TOKEN) or (_required_logon(TOKEN)):
TOKEN=_logon(companyID,username,password)
in_xml="""\
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<VerifyABA xmlns="http://www.lyonsreg.com/WebService/ABAService">
<token>%s</token>
<aba>%s</aba>
</VerifyABA>
</soap:Body>
</soap:Envelope>""" % (TOKEN,aba)
result_xml=_SOAP_post("http://www.lyonsreg.com/WebService/ABAService/VerifyABA",in_xml)
doc=xml.dom.minidom.parseString(result_xml)
response=doc.getElementsByTagName('VerifyABAResult')[0].firstChild.data
return _str_to_bool(response)
if __name__=='__main__':
#Quick Tests
token=_logon('yourcompanyid','username','pw')
print token
assert _required_logon(token)==False
logoff(token)
assert _required_logon(token)==True
token=_logon('yourcompanyid','username','pw')
print token
#actual usage:
assert bool_verify_ABA(token,'abanumber','yourcompanyid','username','pw')==False
Other Sample Code Snippets
Complete source code for the above sample applications and other platform variations is available upon request. Contact us for more information. © 2003-2007 Lyons Commercial Data
© 2003 - 2010 Lyons Commercial Data
Lyons Commercial Data - HomeProducts | Login | Support | Link to Us | Partners | Events | About Lyons | Contact Us |
|