How to use the wikidataintegrator.wdi_core.FormatterWithHeader function in wikidataintegrator

To help you get started, we’ve selected a few wikidataintegrator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SuLab / WikidataIntegrator / wikidataintegrator / wdi_core.py View on Github external
def __init__(self, header, **kwargs):
        super(FormatterWithHeader, self).__init__(**kwargs)
        self.header = header
        # Override the normal format method
        self.format = self.first_line_format
github SuLab / WikidataIntegrator / wikidataintegrator / wdi_core.py View on Github external
logger = logging.getLogger(logger_name)
        logger.setLevel(logging.DEBUG)

        log_file_name = os.path.join(log_dir, log_name)

        file_handler = logging.FileHandler(log_file_name, mode='a')
        file_handler.setLevel(logging.DEBUG)

        fmt = '%(levelname)s{delimiter}%(asctime)s{delimiter}%(message)s'.format(delimiter=delimiter)
        if header:
            header = header if header.startswith("#") else "#" + header
            header += "\n" + delimiter.join(names)
            formatter = FormatterWithHeader(header, fmt=fmt, datefmt='%m/%d/%Y %H:%M:%S')
        else:
            formatter = FormatterWithHeader(delimiter.join(names), fmt=fmt, datefmt='%m/%d/%Y %H:%M:%S')
        file_handler.setFormatter(formatter)
        logger.addHandler(file_handler)

        cls.logger = logger
github SuLab / WikidataIntegrator / wikidataintegrator / wdi_core.py View on Github external
run_id = time.strftime('%Y%m%d_%H:%M', time.localtime())
            log_name = "WD_bot_run-{}.log".format(run_id)

        logger = logging.getLogger(logger_name)
        logger.setLevel(logging.DEBUG)

        log_file_name = os.path.join(log_dir, log_name)

        file_handler = logging.FileHandler(log_file_name, mode='a')
        file_handler.setLevel(logging.DEBUG)

        fmt = '%(levelname)s{delimiter}%(asctime)s{delimiter}%(message)s'.format(delimiter=delimiter)
        if header:
            header = header if header.startswith("#") else "#" + header
            header += "\n" + delimiter.join(names)
            formatter = FormatterWithHeader(header, fmt=fmt, datefmt='%m/%d/%Y %H:%M:%S')
        else:
            formatter = FormatterWithHeader(delimiter.join(names), fmt=fmt, datefmt='%m/%d/%Y %H:%M:%S')
        file_handler.setFormatter(formatter)
        logger.addHandler(file_handler)

        cls.logger = logger
github SuLab / WikidataIntegrator / wikidataintegrator / wdi_core.py View on Github external
if not log_name:
            run_id = time.strftime('%Y%m%d_%H:%M', time.localtime())
            log_name = "WD_bot_run-{}.log".format(run_id)

        logger = logging.getLogger('WD_logger')
        logger.setLevel(logging.DEBUG)

        log_file_name = os.path.join(log_dir, log_name)

        file_handler = logging.FileHandler(log_file_name, mode='a')
        file_handler.setLevel(logging.DEBUG)

        fmt = '%(levelname)s{delimiter}%(asctime)s{delimiter}%(message)s'.format(delimiter=delimiter)
        if header:
            header = header if header.startswith("#") else "#" + header
            formatter = FormatterWithHeader(header, fmt=fmt, datefmt='%m/%d/%Y %H:%M:%S')
        else:
            formatter = logging.Formatter(fmt=fmt, datefmt='%m/%d/%Y %H:%M:%S')
        file_handler.setFormatter(formatter)
        logger.addHandler(file_handler)

        cls.logger = logger
github SuLab / WikidataIntegrator / wikidataintegrator / wdi_core.py View on Github external
def first_line_format(self, record):
        # First time in, switch back to the normal format function
        self.format = super(FormatterWithHeader, self).format
        return self.header + "\n" + self.format(record)