-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreqBookingAPI.py
More file actions
105 lines (84 loc) · 3.88 KB
/
Copy pathreqBookingAPI.py
File metadata and controls
105 lines (84 loc) · 3.88 KB
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
96
97
98
99
100
101
102
103
104
105
# Where the resust to API is sent
import lambda_function as lmbFunction
import intBookingAPI as bookingAPI
import urllib.request
import getpass
import urllib.parse
from xml.dom import minidom
import http.cookiejar
import urllib, base64
from base64 import b64encode
from botocore.vendored import requests
from botocore.vendored.requests.auth import HTTPBasicAuth
from botocore.vendored.requests.auth import _basic_auth_str
import json
import re
import xml.etree.ElementTree as ET
import warnings
import executionCount as exCount
import instanceConfiguration as insConfig
warnings.filterwarnings("ignore")
username = insConfig.userName()
password = insConfig.passWord()
def cancelBookingReq(bookingCenter, bookingID, notifyParticipants, notifyStaff, message):
req = insConfig.reqURL('BookingAPI')
number = exCount.recordCounter('count')
numberOfRecords = exCount.fileLineCounter()
headers = {'Authorization':_basic_auth_str(username,password),"Content-Type": "text/xml;charset=UTF-8","SOAPAction": "cancelBooking"}
request = u"""<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v5="http://v5.api.eclub.procard.dk/">
<soapenv:Header/>
<soapenv:Body>
<v5:cancelBooking>
<bookingKey>
<center>{0}</center>
<id>{1}</id>
</bookingKey>
<notifyParticipants>{2}</notifyParticipants>
<notifyStaff>{3}</notifyStaff>
<message>{4}</message>
</v5:cancelBooking>
</soapenv:Body>
</soapenv:Envelope>""".format(bookingCenter,bookingID,notifyParticipants,notifyStaff,message)
encoded_request = request.encode('utf-8')
#response = requests.post(url=req,headers = headers,data = encoded_request,verify=False)
#root = ET.fromstring(response.content)
try:
erMessage = root.findall(".//errorMessage")
erCode = root.findall(".//errorCode")
exCount.errorsCounter('count')
print(str(bookingCenter)+'book'+str(bookingID),'- Failed with code:', erCode[0].text, ' and message ',erMessage[0].text )
print(number,'/',numberOfRecords,'records have been processed.')
except Exception as e:
exCount.successCounter('count')
print(str(bookingCenter)+'book'+str(bookingID),'- OK.',number,'/',numberOfRecords,'records have been processed.')
if number == numberOfRecords:
successCount = int(exCount.successCounter('total'))
errorCount = int(exCount.errorsCounter('total'))
print('Process completed..\n','Success:',successCount,'Failures:',errorCount)
def cancelPersonParticipation(partCenter, partID, peCenter, peID, UserInterfaceType, sendCancelMessage):
global success
global errors
req = insConfig.reqURL('BookingAPI')
print('We will point to: ',req)
headers = {'Authorization':_basic_auth_str(username,password),"Content-Type": "text/xml;charset=UTF-8","SOAPAction": "cancelPersonParticipation"}
request = u"""<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v5="http://v5.api.eclub.procard.dk/">
<soapenv:Header/>
<soapenv:Body>
<v5:cancelPersonParticipation>
<participationId>
<center>{0}</center>
<id>{1}</id>
</participationId>
<personKey>
<center>{2}</center>
<id>{3}</id>
</personKey>
<userInterfaceType>{4}</userInterfaceType>
<sendCancelMessage>{5}</sendCancelMessage>
</v5:cancelPersonParticipation>
</soapenv:Body>
</soapenv:Envelope>""".format(partCenter, partID, peCenter, peID, UserInterfaceType, sendCancelMessage,req)
encoded_request = request.encode('utf-8')
response = requests.post(url=req,headers = headers,data = encoded_request,verify=False)
print (response.content)
print (str(partCenter)+'part'+str(partID)," had cancellation requests sent to endpoint ",req)