def _domestic_or_international(route_in_file):
    """ Connect to the historical database.
        Search in the airports table for the airports in the route from the file.
        Close the connection to historical database. """

    cursor = None
    historical_db_connection = None
    try:
        historical_db_connection = connect_to_database()
        cursor = historical_db_connection.cursor()
        airports = identify_airports_in_route(route_in_file)
        countries = []
        for airport in airports:
            countries.append(_search_airport_for_country(cursor, airport))
        if _compare_countries(countries) is True:
            return "Domestic"
        else:
            return "International"
    except Exception as e:
        print(e)
    finally:
        if cursor:
            cursor.close()
        if historical_db_connection:
            historical_db_connection.close()
def _validate_fare_class(fare_class_in_file):
    """ Connect to the historical database.
        Search in the fare_class table for the fare class from the file.
        If the fare class does not exist, update the table based on user input.
        Close the connection to historical database. """

    cursor = None
    historical_db_connection = None
    try:
        historical_db_connection = connect_to_database()
        cursor = historical_db_connection.cursor()
        search_results = _search_fare_class_database(cursor,
                                                     fare_class_in_file)
        if search_results is None:
            missing_fare_class = fare_class_in_file[0]
            updated_fare_class = _get_new_fare_class(missing_fare_class)
            _update_database_with_new_fare_class(historical_db_connection,
                                                 cursor, missing_fare_class,
                                                 updated_fare_class)
            search_results = (updated_fare_class, missing_fare_class)
        return search_results
    except Exception as e:
        print(e)
    finally:
        if cursor:
            cursor.close()
        if historical_db_connection:
            historical_db_connection.close()
def _validate_hotel_state(state_in_file, country_in_file):

    cursor = None
    historical_db_connection = None
    try:
        historical_db_connection = connect_to_database()
        cursor = historical_db_connection.cursor()
        search_results = _search_by_subdivision_alias(cursor, state_in_file,
                                                      country_in_file)
        if search_results is None:
            search_results = _search_by_iso_2_code_with_country(
                cursor, state_in_file, country_in_file)
            if search_results is None:
                search_results = _search_by_iso_2_code_without_country(
                    cursor, state_in_file, country_in_file)
                if search_results is None:
                    search_results = _search_similar_subdivisions(
                        cursor, state_in_file, country_in_file)
                    if search_results is None:
                        search_results = _missing_state(
                            cursor, state_in_file, country_in_file)
                        _update_database_with_new_subdivision_alias(
                            historical_db_connection, cursor, state_in_file,
                            search_results)
        return search_results
    except Exception as e:
        print(e)
    finally:
        if cursor:
            cursor.close()
        if historical_db_connection:
            historical_db_connection.close()
def _hotel_country_from_db(country_in_file):

    cursor = None
    historical_db_connection = None
    try:
        historical_db_connection = connect_to_database()
        cursor = historical_db_connection.cursor()
        search_results = _search_by_counrty_alias(cursor, country_in_file)
        if search_results is None:
            search_results = _search_by_iso_2_code(cursor, country_in_file)
            if search_results is None:
                search_results = _search_by_iso_3_code(cursor, country_in_file)
                if search_results is None:
                    search_results = ("", )
        return search_results
    except Exception as e:
        print(e)
    finally:
        if cursor:
            cursor.close()
        if historical_db_connection:
            historical_db_connection.close()
Exemplo n.º 5
0
def _validate_airline_vendor(airline_in_file):
    """ Connect to the historical database.
        Search in the airlines table for the airline from the file.
        If the airline does not exist, update the table based on user input.
        Close the connection to historical database. """

    cursor = None
    historical_db_connection = None
    try:
        historical_db_connection = connect_to_database()
        cursor = historical_db_connection.cursor()
        search_results = _search_airline_database(cursor, airline_in_file)
        if search_results is None:
            missing_airline = airline_in_file[0]
            missing_airline = set_name_to_correct_case(missing_airline)
            update_vendor_code = _get_new_airline_code(cursor, missing_airline)
            if _check_suggested_vendor_code(cursor, update_vendor_code):
                _update_database_with_new_airline_alias(
                    historical_db_connection, cursor, missing_airline,
                    update_vendor_code)
            else:
                iata_numeric, airline_icao, airline_country, airline_active, airline_low_cost = \
                    _collect_additional_new_airline_info(missing_airline, update_vendor_code)
                _update_database_with_new_airline(
                    historical_db_connection, cursor, missing_airline,
                    update_vendor_code, iata_numeric, airline_icao,
                    airline_country, airline_active, airline_low_cost)
                _update_database_with_new_airline_alias(
                    historical_db_connection, cursor, missing_airline,
                    update_vendor_code)
            search_results = (update_vendor_code, missing_airline)
        return search_results
    except Exception as e:
        print(e)
    finally:
        if cursor:
            cursor.close()
        if historical_db_connection:
            historical_db_connection.close()
def _route_destinations_city(route_in_file):
    """ Connect to the historical database.
        Search in the airports table for the airports in the route from the file.
        Close the connection to historical database. """

    cursor = None
    historical_db_connection = None
    try:
        historical_db_connection = connect_to_database()
        cursor = historical_db_connection.cursor()
        airports = identify_airports_in_route(route_in_file)
        destination_city = ""
        for airport in airports:
            destination_city += _search_airport_for_destination_city(cursor, airport)[0] + "/"
        destination_city = destination_city[:-1]
        return destination_city
    except Exception as e:
        print(e)
    finally:
        if cursor:
            cursor.close()
        if historical_db_connection:
            historical_db_connection.close()