Exemplo n.º 1
0
def get_leg_route_number(leg):
    short_path = ['NS1:Verkehrsmittel', 'NS1:Informationen',
                  'NS1:Nummer']  # seems to be identical to 'NS1:ExterneNummer'
    return get_node_text_value(leg, short_path)
Exemplo n.º 2
0
def eval_error_type(response, params, CONFIG):
    """
    Different 500 errors can occur - Below is the v1 documentation (we're using v2) so might be out of date

    FahrplanService_V1_0.wsdl

    SBB successfully operates an online timetable that can be used to perform timetable enquiries and query
    arrival/departure tables, trains/services and other information. The web service enables third parties to query this
    information via a standardised interface and use it in their own applications. In the event of an error, a SOAP
    fault is generated with associated error code. The following error codes are available:

    - SPF-0000: General error. Unidentified cause.
    - SPF-1000: Timetable system responding with error status code. The timetable system's error code is appended to the
                code generated by the timetable service, e.g. SPF_1000_K9260
    - SPF-1001: Technical error during timetable system query, occurs e.g. if the timetable system is unavailable.
    - SPF-2000: Validation error. The request does not conform to the schema.
    - SPF-3000: Error interpreting query. The query is valid but cannot be interpreted.
    - SPF-3100: Error interpreting timetable system response. The timetable system has supplied a response that cannot
                be interpreted.
    - SPF-5000: Not authorised to carry out this operation.
    - SPF-9000: Search query does not contain any entries.


    Known messages / codes that have been encountered so far:

    SPF-1000_C1
    Fahrplansystem Error
    Communication: No server found accepting us. (server is down?)

    SPF-1000_W-K890
    Fahrplansystem Error
    No connections found.

    SPF-1000_F2
    Fahrplansystem Error
    Spool: Error writing the spoolfile.

    SPF-3000
    Request Transformation error
    WSINPHDR:SOAP_Extract

    :param response:
    :param params:
    :return:
    """

    logging.debug(response.content)

    # TODO : this should output proper error logs based on the output from SBB.
    # TODO : The different kind of errors should be pushed to a statsd counter so we can monitor them

    try:
        root = ET.fromstring(response.content)

        # Get the SBB error code (all errors are labeled as 500 in the response)
        error_code_path = [
            'soapenv:Envelope ', 'soapenv:Body', 'soapenv:Fault', 'faultcode'
        ]
        error_code = get_node_text_value(root, error_code_path)

        # Get the SBB error code (all errors are labeled as 500 in the response)
        error_string_path = [
            'soapenv:Envelope ', 'soapenv:Body', 'soapenv:Fault', 'faultstring'
        ]
        error_string = get_node_text_value(root, error_string_path)

        # Get the message associated with the error
        error_msg_path = [
            'soapenv:Envelope ', 'soapenv:Body', 'soapenv:Fault', 'detail'
            'NS5:technicalDetails', 'text'
        ]
        error_msg = get_node_text_value(root, error_msg_path)

        logging.error('Query failed, ERROR {e}'.format(e=response.status_code))
        logging.error(
            'SBB API Error/Fault (Code : String - Technical Details), {c} : {s} - {m}'
            .format(c=error_code, s=error_string, m=error_msg))
        logging.error('Parameters supplies: \n{q}'.format(q=params))
        logging.error('Full response: \n{r}'.format(r=response.content))

        # decide on output behavior:
        #   RETRY / EXIT / SKIP
        if error_code == 'SPF-1000_C1':
            return 'retry'
        elif error_code == 'SPF-1000_F2':
            return 'retry'
        elif error_code == 'SPF-3000':
            return 'retry'
        elif error_code == 'SPF-1000_W-K890':
            return 'skip'

    except:
        send_email(
            'Error processing SBB API response:\n{r}'.format(
                r=response.content), CONFIG)

    return None
Exemplo n.º 3
0
def get_leg_route_category(leg):
    short_path = [
        'NS1:Verkehrsmittel', 'NS1:Informationen', 'NS1:Kategorie',
        'NS1:Abkuerzung'
    ]
    return get_node_text_value(leg, short_path)
Exemplo n.º 4
0
def get_leg_route_line(leg):
    short_path = ['NS1:Verkehrsmittel', 'NS1:Informationen', 'NS1:Linie']
    return get_node_text_value(leg, short_path)
Exemplo n.º 5
0
def get_leg_type(leg):
    short_path = ['NS1:Verkehrsmittel', 'NS1:Typ']
    return get_node_text_value(leg, short_path)
Exemplo n.º 6
0
def get_leg_route_full_name(leg):
    short_path = ['NS1:Verkehrsmittel', 'NS1:Informationen', 'NS1:Name']
    return get_node_text_value(leg, short_path)
Exemplo n.º 7
0
def get_seg_stop_id(segment):
    short_path = [
        'NS1:Haltestelle', 'NS1:Standort', 'NS1:Id', 'NS1:ExterneStationId'
    ]
    return get_node_text_value(segment, short_path).lstrip('0')
Exemplo n.º 8
0
def get_seg_type(segment):
    short_path = ['NS1:Haltestelle', 'NS1:Standort', 'NS1:Typ']
    return get_node_text_value(segment, short_path)
Exemplo n.º 9
0
def get_leg_platform_end(leg):
    short_path = ['NS1:Ankunft', 'NS1:Haltestelle', 'NS1:Gleis', 'NS1:Aktuell']
    return get_node_text_value(leg, short_path)
Exemplo n.º 10
0
def get_leg_station_name_end(leg):
    short_path = ['NS1:Ankunft', 'NS1:Haltestelle', 'NS1:Standort', 'NS1:Name']
    # return remove_non_ascii(get_node_text_value(leg, short_path))
    return get_node_text_value(leg, short_path)
Exemplo n.º 11
0
def get_leg_stop_id_end(leg):
    short_path = [
        'NS1:Ankunft', 'NS1:Haltestelle', 'NS1:Standort', 'NS1:Id',
        'NS1:ExterneStationId'
    ]
    return get_node_text_value(leg, short_path).lstrip('0')
Exemplo n.º 12
0
def get_leg_platform_start(leg):
    short_path = ['NS1:Abfahrt', 'NS1:Haltestelle', 'NS1:Gleis', 'NS1:Aktuell']
    return get_node_text_value(leg, short_path)
Exemplo n.º 13
0
def get_leg_agency_id(leg):
    short_path = [
        'NS1:Verkehrsmittel', 'NS1:Informationen',
        'NS1:TransportUnternehmungCode'
    ]
    return get_node_text_value(leg, short_path)