コード例 #1
0
def _set_handlers(cursor_store, checkpoint_name):
    handlers = ExtractionHandlers()
    handlers.TOTAL_EVENTS = 0

    def handle_error(exception):
        if isinstance(exception, OSError):  # let click handle it
            raise

        errors.ERRORED = True
        if hasattr(exception, "response") and hasattr(exception.response,
                                                      "text"):
            message = f"{exception}: {exception.response.text}"
        else:
            message = exception
        logger.log_error(message)

        message = str(message)
        if not message.lower().startswith("error:"):
            message = f"Error: {message}"

        secho(message, err=True, fg="red")

    handlers.handle_error = handle_error
    if cursor_store:
        handlers.record_cursor_position = lambda value: cursor_store.replace(
            checkpoint_name, value)
        handlers.get_cursor_position = lambda: cursor_store.get(checkpoint_name
                                                                )
    return handlers
コード例 #2
0
def _set_handlers(cursor_store, checkpoint_name):
    handlers = ExtractionHandlers()
    handlers.TOTAL_EVENTS = 0

    def handle_error(exception):
        if isinstance(exception, OSError):  # let click handle it
            raise

        errors.ERRORED = True
        if hasattr(exception, "response") and hasattr(exception.response,
                                                      "text"):
            message = "{}: {}".format(exception, exception.response.text)
        else:
            message = exception
        logger.log_error(message)
        secho(str(message), err=True, fg="red")

    handlers.handle_error = handle_error
    if cursor_store:
        handlers.record_cursor_position = lambda value: cursor_store.replace(
            checkpoint_name, value)
        handlers.get_cursor_position = lambda: cursor_store.get(checkpoint_name
                                                                )
    return handlers