@@ -47,7 +47,7 @@ def send_mrn_request(ws):
4747 """ Create and send MRN request """
4848 mrn_req_json = {
4949 'ID': 2,
50- ' Domain' : mrn_domain,
50+ " Domain" : mrn_domain,
5151 'Key': {
5252 'Name': mrn_item
5353 }
@@ -84,31 +84,36 @@ def processUpdate(ws, message_json):
8484 guid = fields_data["GUID"]
8585 mrn_src = fields_data["MRN_SRC"]
8686
87- print("GUID = %s" % guid)
88- print("FRAG_NUM = %d" % frag_num)
89- print("MRN_SRC = %s" % mrn_src)
87+ # print("GUID = %s" % guid)
88+ # print("FRAG_NUM = %d" % frag_num)
89+ # print("MRN_SRC = %s" % mrn_src)
9090
9191 #fragment_decoded = base64.b64decode(fragment)
9292 print("fragment length = %d" % len(fragment))
9393 if frag_num > 1: # We are now processing more than one part of an envelope - retrieve the current details
9494 guid_index = next((index for (index, d) in enumerate(
9595 _news_envelopes) if d["guid"] == guid), None)
9696 envelop = _news_envelopes[guid_index]
97- if envelop:
97+ if envelop and envelop["data"]["mrn_src"] == mrn_src and frag_num == envelop["data"]["frag_num"] + 1 :
9898 print("process multiple fragments for guid %s" %
9999 envelop["guid"])
100100 # print(envelop)
101101 #print("fragment before merge = %d" % len(envelop["data"]["fragment"]))
102102
103- # Merge incoming fragment to current fragment
103+ # Merge incoming data to existing envelop
104104 envelop["data"]["fragment"] = envelop["data"]["fragment"] + fragment
105+ envelop["data"]["frag_num"] = frag_num
105106
106107 #print("TOT_SIZE from envelop = %d" % envelop["data"]["tot_size"])
107108 #print("fragment after merge = %d" % len(envelop["data"]["fragment"]))
108109 if envelop["data"]["tot_size"] == len(envelop["data"]["fragment"]):
109110 parseNewsData(envelop["data"]["fragment"])
110111 else:
111112 return None
113+ else:
114+ print("Error: Cannot find fragment for GUID %s with matching FRAG_NUM or MRN_SRC %s" % (
115+ guid, mrn_src))
116+ return None
112117 else: # FRAG_NUM:1 The first fragment
113118 tot_size = int(fields_data["TOT_SIZE"])
114119 print("TOT_SIZE = %d" % tot_size)
@@ -146,17 +151,17 @@ def processStatus(ws, message_json):
146151def process_message(ws, message_json):
147152 """ Parse at high level and output JSON of message """
148153 message_type = message_json['Type']
149- message_domain = message_json['Domain']
150154
151155 if message_type == "Refresh":
152- if ' Domain' in message_json:
153- # message_domain = message_json[' Domain' ]
156+ if " Domain" in message_json:
157+ message_domain = message_json[" Domain" ]
154158 if message_domain == "Login":
155159 process_login_response(ws, message_json)
156- elif message_domain == mrn_domain :
160+ elif message_domain:
157161 processRefresh(ws, message_json)
158- elif message_type == "Update" and message_domain == mrn_domain:
159- processUpdate(ws, message_json)
162+ elif message_type == "Update":
163+ if "Domain" in message_json and message_json["Domain"] == mrn_domain:
164+ processUpdate(ws, message_json)
160165 elif message_type == "Status":
161166 processStatus(ws, message_json)
162167 elif message_type == "Ping":
@@ -190,7 +195,7 @@ def send_login_request(ws):
190195 """ Generate a login request from command line data (or defaults) and send """
191196 login_json = {
192197 'ID': 1,
193- ' Domain' : 'Login',
198+ " Domain" : 'Login',
194199 'Key': {
195200 'Name': '',
196201 'Elements': {
@@ -214,9 +219,9 @@ def send_login_request(ws):
214219
215220def on_message(ws, message):
216221 """ Called when message received, parse message into JSON for processing """
217- # print("RECEIVED: ")
222+ print("RECEIVED: ")
218223 message_json = json.loads(message)
219- # print(json.dumps(message_json, sort_keys=True, indent=2, separators=(',', ':')))
224+ print(json.dumps(message_json, sort_keys=True, indent=2, separators=(',', ':')))
220225
221226 for singleMsg in message_json:
222227 process_message(ws, singleMsg)
0 commit comments