# Recipients childRecipients = etree.SubElement(childMessaging, "Recipients") recipients = message[0]["recipients"][0] hasAllNetwork = False if 'line' in recipients: # Scan the 'line' recipients to check if the whole transport network is selected for line in recipients["line"]: hasAllNetwork = hasAllNetwork or (line["id"] == network_id) # If it is, use 'AllNetwork' tag if hasAllNetwork: childAllNetwork = etree.SubElement(childRecipients, "AllNetwork") # Else add the Ineo code of each commercial line in the recipients else: childLines = etree.SubElement(childRecipients, "Lines") for line in recipients["line"]: parameters = {"roid": line["id"]} linePM = synthese.service("LinesListFunction2", parameters) lineCodesStr = linePM["line"][0]["creator_id"] lineCodes = map(lambda x: x.split('|'), lineCodesStr.split(',')) for lineCode in lineCodes: if lineCode[0] == datasource_id: childLine = etree.SubElement(childLines, "Line") childLine.text = lineCode[1] # Print resulting XML to output stream print( etree.tostring(root, pretty_print=True, xml_declaration=True, encoding="iso-8859-1"))
hasAllNetwork = False # Process CommercialLine and TransportNetwork recipients if 'line' in recipients: # Scan the 'line' recipients to check if the whole transport network is selected for line in recipients["line"]: hasAllNetwork = hasAllNetwork or (line["id"] == network_id) # If it is, use 'AllNetwork' tag if hasAllNetwork: childAllNetwork = etree.SubElement(childRecipients, "AllNetwork") # Else add the Ineo code of each commercial line in the recipients else: childLines = etree.SubElement(childRecipients, "Lines") for line in recipients["line"]: parameters = { "roid": line["id"] } linePM = synthese.service("LinesListFunction2", parameters) lineCodesStr = linePM["line"][0]["creator_id"] lineCodes = map(lambda x: x.split('|'), lineCodesStr.split(',')) for lineCode in lineCodes: if lineCode[0] == datasource_id: childLine = etree.SubElement(childLines, "Line") childLine.text = lineCode[1] # Process StopArea recipients if 'stoparea' in recipients: childStopPoints = etree.SubElement(childRecipients, "StopPoints") for stoparea in recipients["stoparea"]: # SYNTHESE has stop area AND/OR stop points recipients, but Ineo expects stop points so we request all the stop points of each stop area recipientId = int(stoparea["id"]) recipientTableId = (recipientId / (2**48))
hasAllNetwork = False if "line" in recipients: # Scan the 'line' recipients to check if the whole transport network is selected for line in recipients["line"]: hasAllNetwork = hasAllNetwork or (line["id"] == network_id) # If it is, use 'AllNetwork' tag if hasAllNetwork: childAllNetwork = etree.SubElement(childRecipients, "AllNetwork") # Else add the Ineo code of each commercial line in the recipients else: childLinesWays = etree.SubElement(childRecipients, "LinesWays") for line in recipients["line"]: linkParameters = line[ "link_parameter"] if "link_parameter" in line else "" parameters = {"roid": line["id"]} linePM = synthese.service("LinesListFunction2", parameters) lineCodesStr = linePM["line"][0]["creator_id"] lineCodes = map(lambda x: x.split('|'), lineCodesStr.split(',')) for lineCode in lineCodes: if lineCode[0] == datasource_id: childLineWay = etree.SubElement(childLinesWays, "LineWay") childLine = etree.SubElement(childLineWay, "Line") childLine.text = lineCode[1] childInWard = etree.SubElement(childLineWay, "InWard") childInWard.text = "non" if linkParameters == "1" else "oui" childOutWard = etree.SubElement(childLineWay, "OutWard") childOutWard.text = "non" if linkParameters == "0" else "oui" # Display screen recipients (bivs) childBivs = etree.SubElement(childRecipients, "Bivs") if "displayscreen" in recipients:
# Network and commercial line recipients hasAllNetwork = False if "line" in recipients: # Scan the 'line' recipients to check if the whole transport network is selected for line in recipients["line"]: hasAllNetwork = hasAllNetwork or (line["id"] == network_id) # If it is, use 'AllNetwork' tag if hasAllNetwork: childAllNetwork = etree.SubElement(childRecipients, "AllNetwork") # Else add the Ineo code of each commercial line in the recipients else: childLinesWays = etree.SubElement(childRecipients, "LinesWays") for line in recipients["line"]: linkParameters = line["link_parameter"] if "link_parameter" in line else "" parameters = { "roid": line["id"] } linePM = synthese.service("LinesListFunction2", parameters) lineCodesStr = linePM["line"][0]["creator_id"] lineCodes = map(lambda x: x.split('|'), lineCodesStr.split(',')) for lineCode in lineCodes: if lineCode[0] == datasource_id: childLineWay = etree.SubElement(childLinesWays, "LineWay") childLine = etree.SubElement(childLineWay, "Line") childLine.text = lineCode[1] childInWard = etree.SubElement(childLineWay, "InWard") childInWard.text = "non" if linkParameters == "1" else "oui" childOutWard = etree.SubElement(childLineWay, "OutWard") childOutWard.text = "non" if linkParameters == "0" else "oui" # Display screen recipients (bivs) childBivs = etree.SubElement(childRecipients, "Bivs") if "displayscreen" in recipients:
# Set value to "ALLER/RETOUR" by default, and remove element if there is no StopPoint childWay = etree.SubElement(childMessaging, "Way") childWay.text = "ALLER/RETOUR" # StopPoint recipients = message[0]["recipients"][0] if 'stoparea' in recipients: childStopPoint = etree.SubElement(childMessaging, "StopPoint") # SYNTHESE has stop area AND/OR stop point recipients, but Ineo expects stop points so we request all the stop points of each stop area recipientId = int(recipients["stoparea"][0]["id"]) recipientTableId = (recipientId / (2**48)) if recipientTableId == 12: # This 'stoparea' recipient is a stop point : find its Ineo code parameters = {"roid": recipientId} stopPointPM = synthese.service("object", parameters) if 'operator_code' in stopPointPM: # Split the operator codes and find the Ineo code stopCodes = map(lambda x: x.split('|'), stopPointPM["operator_code"].split(',')) for stopCode in stopCodes: if stopCode[0] == datasource_id: # Ineo stop point ids start with "MNLP_**_", but this prefix must not be sent to Ineo if stopCode[1].startswith(ineo_stop_point_prefix): # A stop point was found, change value of EndStopPoint to "non" to apply message to this stop point childEndStopPoint.text = "non" childStopPoint.text = stopCode[1][ len(ineo_stop_point_prefix):] break if recipientTableId == 7:
for line in lines: childLine = etree.SubElement(childText, "Line") childLine.text = line # Recipients childRecipients = etree.SubElement(childMessaging, "Recipients") recipients = message[0]["recipients"][0] hasAllNetwork = False if 'line' in recipients: # Scan the 'line' recipients to check if the whole transport network is selected for line in recipients["line"]: hasAllNetwork = hasAllNetwork or (line["id"] == network_id) # If it is, use 'AllNetwork' tag if hasAllNetwork: childAllNetwork = etree.SubElement(childRecipients, "AllNetwork") # Else add the Ineo code of each commercial line in the recipients else: childLines = etree.SubElement(childRecipients, "Lines") for line in recipients["line"]: parameters = { "roid": line["id"] } linePM = synthese.service("LinesListFunction2", parameters) lineCodesStr = linePM["line"][0]["creator_id"] lineCodes = map(lambda x: x.split('|'), lineCodesStr.split(',')) for lineCode in lineCodes: if lineCode[0] == datasource_id: childLine = etree.SubElement(childLines, "Line") childLine.text = lineCode[1] # Print resulting XML to output stream print(etree.tostring(root, pretty_print=True, xml_declaration=True, encoding="iso-8859-1"))