forked from lisi-w/cic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pub_client.py
73 lines (57 loc) · 2.16 KB
/
pub_client.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
import requests
class publisherClient(object):
def __init__(self, cert_fn, hostname, verbose=False):
print("pub client initialized")
self.certFile = cert_fn
self.keyFile = cert_fn
urlbase = 'https://{}/esg-search/ws'.format(hostname)
self.retractUrl = '{}/retract'.format(urlbase)
self.updateUrl = '{}/update'.format(urlbase)
self.publishUrl = '{}/publish'.format(urlbase)
self.deleteUrl = '{}/delete'.format(urlbase)
self.verbose = verbose
def post_data(self, url, data):
resp = requests.post(url, data=data, cert=(self.certFile, self.keyFile), \
verify=False, allow_redirects=True)
if self.verbose:
print(resp.text)
return resp
def publish(self, xmldata):
try:
response = self.post_data(self.publishUrl, xmldata)
except requests.exceptions.SSLError as e:
print("SSL error!", e )
except Exception as e:
print("Some other error!", e )
def update(self, xmldata):
print("updating")
try:
response = self.post_data(self.updateUrl, xmldata)
print(response.text)
except requests.exceptions.SSLError as e:
print("SSL error!", e )
except Exception as e:
print("Some other error!", e )
def retract(self, object_id):
print("retracting")
data = { 'id' : object_id }
try:
response = self.post_data(self.retractUrl, data)
except requests.exceptions.SSLError as e:
print("SSL error!", e )
except Exception as e:
print("Some other error!", e )
# root = etree.fromstring(response.content)
# text = root[0].text
# return (response.status_code, text)
print(response.text)
def delete(self, object_id):
data = { 'id' : object_id }
print (data)
try:
response = self.post_data(self.deleteUrl, data)
except requests.exceptions.SSLError as e:
print("SSL error!", e )
except Exception as e:
print("Some other error!", e )
print(response.text)