Python实现生成日报的示例代码

 更新时间:2023年06月19日 16:38:45   作者:一夜奈何梁山  
这篇文章主要为大家详细介绍了如何利用Python实现生成日报的功能,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下

一:日报生成工具

#!/usr/bin/python
# coding:utf8
class GetHtml(object):
    def __init__(self):
        self._html_head = """<html><body style="background-color:#FAEBD7;">"""
        self._format_html_foot = """<p style="font-family: verdana,arial,
        sans-serif;font-size:10px;font-weight:lighter;">%s</p> """
        self._format_html_head = """<p style="font-family: verdana,arial,
        sans-serif;font-size:%dpx;font-weight:bold;align=center">%s</p> """
        self._html_tail = "</body></html>"
        self._html_p_head = """<p style="font-family: verdana,arial,
        sans-serif;font-size:12px;font-weight:bold;">%s</p> """
        self._table_caption = """ <caption style="caption-side:top;font-size:12px;font-weight:bold;">%s</caption> """
        self._table_head = """<table style="font-family: verdana,arial,
        sans-serif;font-size:11px;color:#000000;border-width: 1px;border-color: #222C44;border-collapse: collapse;" 
        border="1"><tr> """
        self._format_table_th = """<th style="border-width: 1px;padding: 8px;border-style: solid;border-color: 
        #98bf21;background-color: #A7C942;" nowrap>%s</th> """
        self._format_table_td = """<td style="border-width: 1px;padding: 8px;text-align: right;border-style: 
        solid;border-color: #98bf21;background-color: #EAF2D3;" align="center" nowrap>%s</td> """
        self._table_tail = "</table>"
        self._content = ""
        self._table_html = []
    def add_table(self, table_title, th_info, td_info_list):
        table_str = ""
        table_p_head = self._html_p_head % (str(table_title))
        table_str = table_p_head + self._table_head
        # th
        table_str += "<tr>"
        for th in th_info:
            temp_str = self._format_table_th % (str(th))
            table_str += temp_str
        table_str += "</tr>"
        # td
        for td_info in td_info_list:
            table_str += "<tr>"
            for td in td_info:
                temp_str = self._format_table_td % (str(td))
                table_str += temp_str
            table_str += "</tr>"
        table_str += self._table_tail
        self._table_html.append(table_str)
    def add_head(self, head, found_size=18):
        head_str = self._format_html_head % (found_size, str(head))
        self._table_html.append(head_str)
    def add_foot(self, foot):
        foot_str = self._format_html_foot % (str(foot))
        self._table_html.append(foot_str)
    @staticmethod
    def concat_color(a, b):
        """通过a,b对比给a增加高亮显示"""
        cmp_a, cmp_b = float(str(a).strip('%')), float(str(b).strip('%'))
        if cmp_a > cmp_b:
            new_a = '<font color="red">' + '{}↑'.format(a) + '</font>'
        elif cmp_a < cmp_b:
            new_a = '<font color="green">' + '{}↓'.format(a) + '</font>'
        else:
            new_a = a
        return new_a
    def output_html(self):
        """输出HTML文件"""
        html_content = self._html_head
        for s in self._table_html:
            html_content += s
        html_content += self._html_tail
        return html_content

二:日报工具使用方式

生成html对象: html = GetHtml()

给html新增标题: html.add_head(“标题”)

html种增加统计表格

total_table = list()
        total_header = ["日期", "进件总量", "进件完成量", "延时进件量", "卡单量", "通过量", "拒绝量", "人工量",
                        "通过率(%)", "拒绝率(%)", "平均耗时(秒)"]
        # TODO: 查询数据逻辑, 追加到total_table中
        if len(total_table) >= 2:
            # 通过率 拒绝率 平均耗时 增加高亮显示
            total_table[0][8] = html.concat_color(a=total_table[0][8], b=total_table[1][8])
            total_table[0][9] = html.concat_color(a=total_table[0][9], b=total_table[1][9])
            total_table[0][10] = html.concat_color(a=total_table[0][10], b=total_table[1][10])
        html.add_table("表{}-{}授信机审".format(num, get_product_chinese_name(product_name)), total_header, total_table)

输出html整个页面:html.output_html()

三:最终日报生成展示

到此这篇关于Python实现生成日报的示例代码的文章就介绍到这了,更多相关Python生成日报内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • python可视化分析的实现(matplotlib、seaborn、ggplot2)

    python可视化分析的实现(matplotlib、seaborn、ggplot2)

    这篇文章主要介绍了python可视化分析的实现(matplotlib、seaborn、ggplot2),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-02-02
  • windows下安装Python虚拟环境virtualenvwrapper-win

    windows下安装Python虚拟环境virtualenvwrapper-win

    这篇文章主要介绍了windows下安装Python虚拟环境virtualenvwrapper-win,内容超简单,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
    2019-06-06
  • Cython 三分钟入门教程

    Cython 三分钟入门教程

    根据一些我收到的反馈,大家似乎有点混淆——Cython是用来生成 C 扩展到而不是独立的程序的。所有的加速都是针对一个已经存在的 Python 应用的一个函数进行的。
    2009-09-09
  • python tornado协程调度原理示例解析

    python tornado协程调度原理示例解析

    这篇文章主要为大家介绍了python tornado协程调度原理示例解析,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-09-09
  • pytorch 如何查看数据类型和大小

    pytorch 如何查看数据类型和大小

    这篇文章主要介绍了pytorch 实现查看数据类型和大小的操作,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2021-05-05
  • Python创建临时文件和文件夹

    Python创建临时文件和文件夹

    这篇文章主要介绍了Python如何创建临时文件和文件夹,文中讲解非常细致,代码帮助大家更好的理解和学习,感兴趣的朋友可以了解下
    2020-08-08
  • Python爬虫之爬取某文库文档数据

    Python爬虫之爬取某文库文档数据

    这篇文章主要介绍了Python爬虫之爬取某文库文档数据,文中有非常详细的代码示例,对正在学python的小伙伴们有很好地帮助,需要的朋友可以参考下
    2021-04-04
  • Python3标准库总结

    Python3标准库总结

    在本篇内容中我们给大家总结了关于Python3标准库的相关内容,需要的朋友们跟着学习下。
    2019-02-02
  • Python如何快速生成本项目的requeirments.txt实现

    Python如何快速生成本项目的requeirments.txt实现

    本文主要介绍了Python如何快速生成本项目的requeirments.txt实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-03-03
  • Python中PyMySQL的基本操作

    Python中PyMySQL的基本操作

    PyMySQL 遵循 Python 数据库 API v2.0 规范,并包含了 pure-Python MySQL 客户端库,这篇文章主要介绍了Spring DI依赖注入详解,需要的朋友可以参考下
    2022-11-11

最新评论