-
Notifications
You must be signed in to change notification settings - Fork 2
/
cir.py
96 lines (71 loc) · 2.79 KB
/
cir.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!python
#!/usr/bin/python
import logging
import random
import string
import ConfigParser
import os.path
import sys
from suds import MethodNotFound
from suds.client import Client
from suds.wsse import Security, UsernameToken
from suds.sax.element import Element
from suds.sax.attribute import Attribute
from suds.xsd.sxbasic import Import
WEBSERVICE_URL = 'http://webservice.rechtspraak.nl/cir.asmx'
NS_WSA = ('wsa', 'http://schemas.xmlsoap.org/ws/2004/08/addressing')
MUST_UNDERSTAND = Attribute('SOAP-ENV:mustUnderstand', 'true')
if not os.path.isfile('credentials.ini'):
print 'First create or request credentials at:\nhttp://www.rechtspraak.nl/Uitspraken-en-Registers/centraal-insolventieregister/Pages/Aanvraag-Autorisatie.aspx'
sys.exit(-1)
Config = ConfigParser.ConfigParser()
Config.read("credentials.ini")
USERNAME = Config.get('Login', 'Username')
PASSWORD = Config.get('Login', 'Password')
def main():
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
client = Client('%s?wsdl' % WEBSERVICE_URL)
add_security(client, USERNAME, PASSWORD)
add_addressing(client, WEBSERVICE_URL)
# client.service.GetLastUpdate()
# client.service.searchByDate("2014-07-14T00:00:00", "01", "Uitspraken faillissement")
method = get_method(client, 'GetLastUpdate')
print method()
def add_security(client, user, passwd):
sec = Security()
token = UsernameToken(user, passwd)
token.setnonce()
token.setcreated()
sec.tokens.append(token)
client.set_options(wsse=sec)
def add_addressing(client, webservice_url):
headers = []
addr = Element('Address', ns=NS_WSA).setText('http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous')
headers.append(Element('Element').addPrefix(p='SOAP-ENC', u='http://www.w3.org/2003/05/soap-encoding'))
headers.append(Element('ReplyTo', ns=NS_WSA).insert(addr).append(MUST_UNDERSTAND))
headers.append(Element('To', ns=NS_WSA).setText(webservice_url).append(MUST_UNDERSTAND))
headers.append(addr)
headers.append(Element('MessageID', ns=NS_WSA).setText('urn:uuid:%s' % generate_messageid()))
client.set_options(soapheaders=headers)
def get_method(client, method):
try:
m = getattr(client.service, method)
action = client.wsdl.services[0].ports[0].methods[method].soap.action
action = action.replace('"', '')
except MethodNotFound:
return None
action_header = Element('Action', ns=NS_WSA).setText(action)
client.options.soapheaders.append(action_header)
return m
def generate_messageid():
fmt = 'xxxxxxxx-xxxxx'
resp = ''
for c in fmt:
if c == '-':
resp += c
else:
resp += string.hexdigits[random.randrange(16)]
return resp
if __name__ == '__main__':
main()