-
Notifications
You must be signed in to change notification settings - Fork 0
/
updatesr2.py
183 lines (169 loc) · 5.33 KB
/
updatesr2.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import json
from swagger_server import service
import collections
from operator import methodcaller
import os
from datetime import datetime
import time
import uuid
'''
Here we try to check the validity of the services
'''
''' Read current valid services '''
dataold = []
fname = 'import/vts.dat'
if os.path.isfile(fname):
with open(fname) as f:
dataold = json.loads(f.read())
''' Read all services '''
fname = 'import/vtsnew.dat'
with open(fname) as f:
data = json.loads(f.read())
os.remove(fname)
''' Set all services to valid for the check '''
fname = 'import/vts.dat'
with open(fname,'w') as f:
f.write(json.dumps(data))
''' Set the set to include only new or unvalid services '''
for item in dataold:
if item in data:
data.remove(item)
''' Check the set of new or unvalid services '''
for srv in data:
ret = service.get_voyageplan(srv['endpointUri'])
if (ret.status_code == 500) and (ret.text == 'SSLError'):
print(srv['name'])
else:
dataold.append(srv)
''' Save the modified set of valid services '''
with open(fname,'w') as f:
f.write(json.dumps(dataold))
''' Read current valid services '''
dataold = []
fname = 'import/services.dat'
if os.path.isfile(fname):
with open(fname) as f:
dataold = json.loads(f.read())
''' Read all services '''
fname = 'import/servicesnew.dat'
with open(fname) as f:
data = json.loads(f.read())
os.remove(fname)
''' Set all services to valid for the check '''
fname = 'import/services.dat'
with open(fname,'w') as f:
f.write(json.dumps(data))
''' Set the set to include only new or unvalid services '''
for item in dataold:
if item in data:
data.remove(item)
''' Check the set of new or unvalid services '''
for srv in data:
ret = service.get_voyageplan(srv['endpointUri'])
if (ret.status_code == 500) and (ret.text == 'SSLError'):
print(srv['name'])
else:
dataold.append(srv)
''' Save the modified set of valid services '''
with open(fname,'w') as f:
f.write(json.dumps(dataold))
''' Read current valid services '''
dataold = []
fname = 'import/vessels.dat'
if os.path.isfile(fname):
with open(fname) as f:
dataold = json.loads(f.read())
''' Read all services '''
fname = 'import/vesselsnew.dat'
with open(fname) as f:
data = json.loads(f.read())
os.remove(fname)
''' Set all services to valid for the check '''
fname = 'import/vessels.dat'
with open(fname,'w') as f:
f.write(json.dumps(data))
''' Set the set to include only new or unvalid services '''
for item in dataold:
if item in data:
data.remove(item)
''' Check the set of new or unvalid services '''
for srv in data:
ret = service.get_voyageplan(srv['endpointUri'])
if (ret.status_code == 500) and (ret.text == 'SSLError'):
print(srv['name'])
else:
dataold.append(srv)
''' Save the modified set of valid services '''
with open(fname,'w') as f:
f.write(json.dumps(dataold))
textmessage='''<?xml version="1.0" encoding="utf-8"?>
<textMessage
xmlns:xsi="http:https://www.w3.org/2001/XMLSchema-instance"
xmlns="http:https://stmvalidation.eu/schemas/textMessageSchema_1_3.xsd">
<textMessageId>urn:mrn:stm:txt:furuno:''' + str(uuid.uuid4()) + '''</textMessageId>
<author>Test robot</author>
<from>urn:mrn:stm:org:sma</from>
<serviceType>SHIP-VIS</serviceType>
<createdAt>''' + datetime.utcnow().replace(microsecond=0).isoformat() + 'Z' + '''</createdAt>
<subject>Automatic test message</subject>
<body>This message is sent in order to test if text messages can be sent to this VIS instance</body>
</textMessage>
'''
''' Read current valid services '''
dataold = []
fname = 'import/text.dat'
if os.path.isfile(fname):
with open(fname) as f:
dataold = json.loads(f.read())
''' Read all services '''
fname = 'import/textnew.dat'
with open(fname) as f:
data = json.loads(f.read())
os.remove(fname)
''' Set all services to valid for the check '''
fname = 'import/text.dat'
with open(fname,'w') as f:
f.write(json.dumps(data))
''' Set the set to include only new or unvalid services '''
for item in dataold:
if item in data:
data.remove(item)
''' Check the set of new or unvalid services '''
for srv in data:
ret = service.post_text(srv['endpointUri'], textmessage)
if ret.status_code == 405 or ret.status_code == 500 or ret.status_code == 501:
print(srv['name'])
else:
dataold.append(srv)
''' Save the modified set of valid services '''
with open(fname,'w') as f:
f.write(json.dumps(dataold))
''' Read current valid services '''
dataold = []
fname = 'import/ports.dat'
if os.path.isfile(fname):
with open(fname) as f:
dataold = json.loads(f.read())
''' Read all services '''
fname = 'import/portsnew.dat'
with open(fname) as f:
data = json.loads(f.read())
os.remove(fname)
''' Set all services to valid for the check '''
fname = 'import/ports.dat'
with open(fname,'w') as f:
f.write(json.dumps(data))
''' Set the set to include only new or unvalid services '''
for item in dataold:
if item in data:
data.remove(item)
''' Check the set of new or unvalid services '''
for srv in data:
ret = service.createpcmqueue(srv['instanceId'])
if ret.status_code == 200:
dataold.append(srv)
else:
print(srv['unlocode'], ret.status_code, ret.text)
''' Save the modified set of valid services '''
with open(fname,'w') as f:
f.write(json.dumps(dataold))