コード例 #1
0
def process_operation(uuid, operation):
    logger.info(
        f"Processing operation '{operation}' on data associated with UUID '{uuid}'..."
    )

    try:
        stored_data = data_store.get(uuid)
        operation_func = get_operation(operation)
        result = operation_func(stored_data)
    except KeyError:
        logger.warning(f"Cannot retrieving data associated with UUID '{uuid}'")
        return jsonify({
            "status": "failed",
            "message": "Cannot retrieve data",
            "result": None
        })
    except NoSuchOperationError:
        logger.warning(f"Cannot find operation '{operation}'")
        return jsonify({
            "status": "failed",
            "message": f"No such '{operation}'",
            "result": None
        })

    logger.warning(
        f"Operation '{operation}' on data associated with UUID '{uuid}' finished successfully!"
    )

    return jsonify({
        "status": "success",
        "message": "Result completed",
        "result": result
    })
コード例 #2
0
ファイル: app.py プロジェクト: telsonfs/codenation
def retrieve_data(uuid):
    logger.info(f"Retrieving data associated with UUID '{uuid}'")
    try:
        data = data_store.get(uuid)

    except KeyError:
        logger.warning(f"cannot retrieve data associated with UUID '{uuid}'")
        return jsonify({"status": "failed", "message": "data cannot be retrieved", "data": []})

    logger.info(f"Data associated with UUID '{uuid}' retrieved sucessfully")

    return jsonify({"status": "success", "message": "data retrieved sucessfully", "data": data})
コード例 #3
0
def retrieve_data():
    logger.info(f"Retrieving data associated with uuid '{uuid}'...")

    try:
        stored_data = data_store.get(uuid)
    except KeyError:
        logger.warning(f"Cannot retrieve data associated with uuid '{uuid}'...")
        return jsonify({"status": "failed", "message": "data cannot be retrieved", "data": []})
            # ao invés de retornar "none", peço para retornar uma lista vazia => "[]"
            # tanto o "none" quanto a lista vazia vai significar erro
            # não é possível iterar com "none", mas é possível fazer com lista vazia
    logger.info(f"Data associated with uuid '{uuid}' retrieved successfully")
    return jsonify({"status": "failed", "message": "data retrieved successfully", "data": stored_data})
コード例 #4
0
ファイル: app.py プロジェクト: Xeslley/Primeira_API_REST
def atempt_get_data(uuid):
    raw_stored_data = []
    try:
        raw_stored_data = data_store.get(uuid)
    except KeyError:
        logger.warning(f"Cannot retrieve data associated with UUID '{uuid}'.")

        return jsonify({
            "status": "failed",
            "message": "data cannot be retrieved.",
            "data": []
        })
    return raw_stored_data
コード例 #5
0
ファイル: app.py プロジェクト: telsonfs/codenation
def operation_data(uuid, operation):
    list_operations = ['max', 'min', 'mean']
    if operation not in list_operations:
        return jsonify({"status": "failed", "message": "invalid operation", "data": []})

    logger.info(f"Retrieving data associated with UUID '{uuid}'")

    try:
        data = data_store.get(uuid)

    except KeyError:
        logger.warning(f"cannot retrieve data associated with UUID '{uuid}'")
        return jsonify({"status": "failed", "message": "data cannot be retrieved", "data": []})

    if operation == 'max':
        return jsonify({"status": "success", "message": "operation successfuly", "max": max(data)})
    elif operation == 'min':
        return jsonify({"status": "success", "message": "operation successfuly", "max": min(data)})
    elif operation == 'mean':
        return jsonify({"status": "success", "message": "operation successfuly", "mean": mean(data)})
コード例 #6
0
ファイル: app.py プロジェクト: murilocaldeira/lista_api_py
def retrieve_data(uuid):
    logger.info(f'Retrieving data associated with UUID `{uuid}` ...')

    try:
        retrivied_data = data_store.get(uuid)
    except KeyError:
        logger.warning(f'Cannot retieve data associated with `{uuid}` ')

        return jsonify({
            'status': 'failed',
            'message': 'data cannot be retieved',
            'data': []
        })

    logger.info(f'Data associated with UUID `{uuid}` retrieved successfuly')

    return jsonify({
        'status': 'success',
        'message': 'data retieved successfuly',
        'data': retrivied_data
    })
コード例 #7
0
ファイル: app.py プロジェクト: murilocaldeira/lista_api_py
def process_operation(uuid, operation):
    logger.info(
        f'Processing operation  `{operation}` on data associated with UUID `{uuid}`...'
    )

    try:
        stored_data = data_store.get(uuid)

        operation_func = get_operation(operation)

        result = operation_func(stored_data)
    except KeyError:
        logger.warning(f'Cannot retrieve data associated with UUID `{uuid}`')

        return jsonify({
            'status': 'failed',
            'message': 'data cannot be retieved',
            'result': None
        })
    except NoSuchOperationError:
        logger.warning(f'Cannot find operation `{operation}`')

        return jsonify({
            'status': 'failed',
            'message': f'no such `{operation}`',
            'result': None
        })

    logger.info(
        f'Operation `{operation}` on data associatd wwith UUID `{uuid}` fineshed successfuly'
    )

    return jsonify({
        'status': 'success',
        'message': 'result completed',
        'result': result
    })
コード例 #8
0
    except KeyError:
        logger.warning(f"Cannot retrieve data associated with uuid '{uuid}'...")
        return jsonify({"status": "failed", "message": "data cannot be retrieved", "data": []})
            # ao invés de retornar "none", peço para retornar uma lista vazia => "[]"
            # tanto o "none" quanto a lista vazia vai significar erro
            # não é possível iterar com "none", mas é possível fazer com lista vazia
    logger.info(f"Data associated with uuid '{uuid}' retrieved successfully")
    return jsonify({"status": "failed", "message": "data retrieved successfully", "data": stored_data})

#  criação de endpoint para realizar operações em cima dos dados que estão salvos
@app.route("/data/<uuid>/<operation>", method = ["GET"])
def process.operation(uuid, operation):
    logger.info(f"Processing operation '{operation}' on data associated with UUID '{uuid}'...")

    try:
        stored_data = data_store.get(uuid)
        operation_func = get_operation(operation)
        result = operation_func(stored_data)
    except KeyError:
        logger.warning(f"Cannot retrieve data associated with uuid '{uuid}'...")
        return jsonify({"status": "failed", "message": "data cannot be retrieved", "result": None})
    except NoSuchOperationError:
        logger.warning(f"Cannot find operation '{operation}'")
        return jsonify({"status": "failed", "message": f"no such '{operation}'", "result": None})
    logger.info(f"Operation '{operation}' on data associated with UUID '{uuid}' finished successfully")
    return jsonify({"status": "success", "message": "result completed", "result": result})

class NoSuchOperationError(Exception):
    pass

def get_operation(operation_name):