0

我编写了一个脚本来为 .CSV 和 .xlsx 格式的设备生成报告,但我还需要使用 Jinja2 将 HTML 格式添加到我的项目中。我是这个模板的新手,如果你能帮我将此格式添加到我的脚本中,我将不胜感激。我正在使用“Fire”从终端运行它。

 def __init__(self, endpoint: str, api_key: str, file_name: Optional[str] = None, fmt="csv", verbose=False):
        logging.getLogger("urllib3.connectionpool").setLevel(logging.ERROR)
        if verbose:
            _logger.setLevel(logging.DEBUG)

        self.fmt = fmt
        self.file_name = file_name
        self.wrapper = ApiWrapper(endpoint, api_key)

    def main_report(self, agent_id=None, rtd=False):
        add_rtd_data = rtd
        start = time.time()
        builder = ReportBuilderFactory().build(fmt=self.fmt)

        file_name = self._get_file_name(agent_id)
        builder.create(file_name)
        _logger.info("The Output file is created")
        row = builder.header(self._header_labels(rtd))
        _logger.info("The Headers are specified")

        instructions = self._columns(add_rtd_data)
        _logger.info("Columns are fetched to the output file")

        if agent_id is not None:
            agent_id_list = agent_id
        else:
            agent_id_list = self.wrapper.get_all_agent_ids

        for agent_id in agent_id_list:
            device_list = self.wrapper.device_list(agent_id, add_rtd_data)
            _logger.info("All the devices fetched with their agent id")
            for device in device_list:
                row = self._write_row(device, agent_id, instructions, row, builder)
        builder.close()
        _logger.info("File `%s.%s` is populated successfully", file_name, self.fmt)

        total_call, remaining = self.wrapper.api_call_counter()
        _logger.info("Total number of calls which are used :%s", total_call)
        _logger.info("The number of remaining daily call :%s", remaining)
        time_passed = (time.time() - start)
        _logger.info('consumed Time for preparation of the Report: %s sec', time_passed)

我已经编写了两个不同的函数“excel_writer”和“csv_writer”来制作这两种格式。

4

0 回答 0