日志格式如下,思路是如果检测到文件中的内容为5位或者8位,即12.11或18.12.11,同时存在.即认为当前行为日期数据
仅作为方便查看日志使用,生成脚本时过滤此行。每次读取到空白行的时候则认为下一条记录为新一天的记录,
另外如果读取到====则认为本周的所有记录已经结束,可生成并退出脚本 12.21
剩余寿命列表 12.20
监控换刀记录表 ===============================================
===============================================
脚本

# -*- coding: utf-8 -*-
"""
12.22 2:12AM
"""
#import time
import datetime
import xlwt now=datetime.datetime.now()
workbook=xlwt.Workbook(encoding='utf-8')
worksheet = workbook.add_sheet('Sheet1')
count=1#序号
newDay=1#是否为另一天的记录
f=open(r"C:\Users\Dell\Desktop\a.txt")
i=4#行号
hour=6#工时
context=0
ids=1
thing=2#工作事项
project=3#所属项目
skill=4#技术点分解描述
other=5#需要协调内容(多人接口联调、现场测试、客户试用等等)
planStart=7#计划开始时间
planEnd=8#计划结束时间
start=9#时间开始时间
end=10#时间完成时间
statu=11#完成状态
backup=12#总结备案 #样式
borders = xlwt.Borders() # Create borders borders.left = xlwt.Borders.THIN # 添加边框-虚线边框
borders.right = xlwt.Borders.THIN # 添加边框-虚线边框
borders.top = xlwt.Borders.THIN # 添加边框-虚线边框
borders.bottom = xlwt.Borders.THIN # 添加边框-虚线边框
borders.left_colour = 0x08 # 边框上色
borders.right_colour = 0x08
borders.top_colour = 0x08
borders.bottom_colour = 0x08 #列宽
worksheet.col(context).width=256*10
worksheet.col(ids).width=256*8
worksheet.col(thing).width=256*30
worksheet.col(project).width=256*10
worksheet.col(skill).width=256*20
worksheet.col(other).width=256*25
worksheet.col(hour).width=256*10
worksheet.col(planStart).width=256*25
worksheet.col(planEnd).width=256*25
worksheet.col(start).width=256*25
worksheet.col(end).width=256*25
worksheet.col(statu).width=256*12
worksheet.col(backup).width=256*22
#创建一个样式----------------------------
stylefirstRow = xlwt.XFStyle()
stylefirstRow.borders = borders
pattern = xlwt.Pattern()
pattern.pattern =xlwt. Pattern.SOLID_PATTERN
pattern.pattern_fore_colour = xlwt.Style.colour_map['gold']
#设置单元格背景色为黄色
stylefirstRow.pattern = pattern
al = xlwt.Alignment()
al.horz = 0x02 # 设置水平居中
al.vert = 0x01 # 设置垂直居中
al.wrap=1 #自动换行
stylefirstRow.alignment = al
font = xlwt.Font() # 为样式创建字体
#font.name = 'Times New Roman'
font.name = u'微软雅黑'
#font.bold = True # 黑体
#font.underline = True # 下划线
#font.italic = True # 斜体字
font.height=0x00C8*1.6 # C8 in Hex (in decimal) = 10 points in height.
#font.colour_index=48#蓝色
#font.colour_index=2#红色
#font.colour_index=59#灰色
#font.colour_index=44#浅蓝色
stylefirstRow.font = font # 设定样式
#第二行样式----------------------------
stylesecondRow = xlwt.XFStyle()
stylesecondRow.borders = borders
font2 = xlwt.Font() # 为样式创建字体
font2.name = u'微软雅黑'
font2.height=0x00C8*1.4 # C8 in Hex (in decimal) = 10 points in height.
stylesecondRow.font = font2 # 设定样式
stylesecondRow.alignment = al
#第3行样式----------------------------
style3Row = xlwt.XFStyle()
style3Row.borders = borders
font3 = xlwt.Font() # 为样式创建字体
font3.name = u'微软雅黑'
font3.height=0x00C8 # C8 in Hex (in decimal) = 10 points in height.
font3.colour_index=48#蓝色
style3Row.font = font3 # 设定样式
#style3Row.alignment = al
#统一字体
fontx = xlwt.Font() # 为样式创建字体
fontx.name = u'微软雅黑'
fontx.height=0x00C8*1.2 # C8 in Hex (in decimal) = 10 points in height.
#灰色背景
styleGrayRow = xlwt.XFStyle()
styleGrayRow.borders = borders
styleGrayRow.font=fontx
patternGray = xlwt.Pattern()
patternGray.pattern =xlwt. Pattern.SOLID_PATTERN
patternGray.pattern_fore_colour = xlwt.Style.colour_map['gray25']
styleGrayRow.pattern=patternGray
styleGrayRow.alignment = al #浅绿背景
styleLightGreenRow = xlwt.XFStyle()
styleLightGreenRow.borders = borders
styleLightGreenRow.font=fontx
patternLightGreen = xlwt.Pattern()
patternLightGreen.pattern =xlwt. Pattern.SOLID_PATTERN
patternLightGreen.pattern_fore_colour = xlwt.Style.colour_map['light_green']
styleLightGreenRow.pattern=patternLightGreen
styleLightGreenRow.alignment=al
styleLightGreenRow.alignment = al
#绿色背景
styleGreenRow = xlwt.XFStyle()
styleGreenRow.borders = borders
styleGreenRow.font=fontx
patternGreen = xlwt.Pattern()
patternGreen.pattern =xlwt. Pattern.SOLID_PATTERN
patternGreen.pattern_fore_colour = xlwt.Style.colour_map['green']
styleGreenRow.pattern=patternGreen
#设置单元格背景色
styleGreenRow.pattern = patternGreen
styleGreenRow.alignment = al #红色字
redstyle = xlwt.XFStyle()
redstyle.borders = borders
fontred= xlwt.Font() # 为样式创建字体
fontred.name = u'微软雅黑'
fontred.height=0x00C8*1.2 # C8 in Hex (in decimal) = 10 points in height.
fontred.colour_index=2#红色
redstyle.font=fontred
redstyle.pattern=patternGray
redstyle.alignment = al
#通用style
styleCommon = xlwt.XFStyle()
styleCommon.borders = borders
styleCommon.font=fontx
styleCommon.alignment = al
#模板内容
worksheet.write_merge(0, 0,0,12, label = "产品开发部工作周报",style=stylefirstRow)
worksheet.write_merge(1, 1,5,7, label = "张三",style=stylesecondRow)
worksheet.write_merge(2, 2,0,12, label = "注:每周五时做本周工作总结(关表),同时做下周工作计划(开表),必要时下周一调整;",style=style3Row)
worksheet.write(3, context, label = "内容",style=styleGrayRow)
worksheet.write(3, ids, label = "序号",style=styleGrayRow)
worksheet.write(3, thing, label = "工作事项",style=styleGrayRow)
worksheet.write(3, project, label = "所属项目",style=styleGrayRow)
worksheet.write(3, skill, label = "技术点分解描述",style=styleGrayRow)
worksheet.write(3, other, label = "需要协调内容(多人接口联调、现场测试、客户试用等等)",style=redstyle)
worksheet.write(3, hour, label = "工作估时",style=styleGrayRow)
worksheet.write(3, planStart, label = "计划开始时间",style=styleGrayRow)
worksheet.write(3, planEnd, label = "计划结束时间",style=styleGrayRow)
worksheet.write(3, start, label = "实际开始时间",style=styleGreenRow)
worksheet.write(3, end, label = "实际开始时间",style=styleGreenRow)
worksheet.write(3, statu, label = "完成状态",style=styleGreenRow)
worksheet.write(3, backup, label = "总结备案",style=styleGreenRow )
for line in f:
line=line.replace('\n','')
#如果上一次获取到的行为空格,则认为当前行为日期,直接跳过
if newDay==1:
newDay=0
#搜索到##则认为一周结束
if line.find("====")!=-1:
break
else:
#print strTime
#如果获取的内容为空格则开始新一天的数据
if line=="":
#更新当前的日期
newDay=1
now=now+datetime.timedelta(days=-1)
else:
newDay=0#置为非新一天的数据
# print len(line)#==8 or line.count==5)
if (len(line)==8 or len(line)==5) and line.find(".")!=-1:
continue#print line.find(".")
else:
worksheet.write(i, ids, label = count,style=styleCommon)
worksheet.write(i, thing, label = line,style=styleCommon)
worksheet.write(i, project, label = "",style=styleCommon)
worksheet.write(i, skill, label = "",style=styleCommon)
worksheet.write(i, other, label = "",style=styleCommon)
worksheet.write(i, hour, label = "",style=styleCommon)
worksheet.write(i, planStart, label = now.strftime("%Y-%m-%d"),style=styleCommon)
worksheet.write(i, planEnd, label = now.strftime("%Y-%m-%d"),style=styleCommon)
worksheet.write(i, start, label = now.strftime("%Y-%m-%d"),style=styleCommon)
worksheet.write(i, end, label = now.strftime("%Y-%m-%d"),style=styleCommon)
worksheet.write(i, statu, label = "完成",style=styleCommon)
worksheet.write(i, backup, label = "",style=styleCommon)
print now.strftime("%Y-%m-%d") +"***"+line.decode('utf-8').encode('cp936')
i=i+1
count=count+1
#print strTime
worksheet.write_merge(4, count+4-2,0,0, label = "本周工作总结",style=styleLightGreenRow)
f.close()
workbook.save(r"C:\Users\Dell\Desktop\\"+"产品开发周报_张三_".decode('utf-8').encode('cp936')+datetime.datetime.now().strftime("%Y_%m_%d")+".xlsx")

代码:github

使用py,根据日志记录自动生成周报的更多相关文章

  1. pycharm中每次创建py文件时就自动生成代码头,以及出现SyntaxError:Non-ASCII 。。。问题

    我们在pycharm中执行py文件的时候,可能会出现以下错误 这是因为你没有制定编码格式,这时候你需要在文件最开始制定编码格式,代码如下 #!/user/bin/env python #-*- cod ...

  2. wpf 全局异常捕捉+错误日志记录+自动创建桌面图标

    /// /// 创建桌面图标 /// public static void CreateShortcutOnDesktop(string LnkName) { String shortcutPath ...

  3. 利用paramiko的demo_simple.py进行日志记录时遇到的特殊字符

    特殊字符列表: 回车 "\r" "\x13" 响铃 "\x07" 换行 "\n" "\x10" &q ...

  4. (转)解释一下SQLSERVER事务日志记录

    本文转载自桦仔的博客http://www.cnblogs.com/lyhabc/archive/2013/07/16/3194220.html 解释一下SQLSERVER事务日志记录 大家知道在完整恢 ...

  5. 解释一下SQLSERVER事务日志记录

    解释一下SQLSERVER事务日志记录 大家知道在完整恢复模式下,SQLSERVER会记录每个事务所做的操作,这些记录会存储在事务日志里,有些软件会利用事务日志来读取 操作记录恢复数据,例如:log ...

  6. ibatis实战之插入数据(自动生成主键)

    ibatis实战之插入数据(自动生成主键) --------- 如果你将数据库设计为使用自动生成的主键,就可以使用ibatis的<selectKey>元素(该元素是<insert&g ...

  7. Pycharm 设置python文件自动生成头部信息模板

    设置头部信息路径: 打开File—Settings—Editor—File and Code Templates—Python Script 输入要自动生成的头部信息模板 这样,新建py文件就会自动生 ...

  8. mysql数据库安全性配置——日志记录

    一:开启数据库日志记录 (1)在查看数据库是否开启日志记录,默认是OFF,即关闭状态.(可在数据库中执行该查询语句,也可在服务器端执行) show variables like 'log_bin'; ...

  9. iBatis——自动生成DAO层接口提供操作函数(详解)

    iBatis——自动生成DAO层接口提供操作函数(详解) 在使用iBatis进行持久层管理时,发现在使用DAO层的updateByPrimaryKey.updateByPrimaryKeySelect ...

随机推荐

  1. 从壹开始前后端分离 [ vue + .netcore 补充教程 ] 三十║ Nuxt实战:动态路由+同构

    上期回顾 说接上文<二九║ Nuxt实战:异步实现数据双端渲染>,昨天咱们通过项目二的首页数据处理,简单了解到了 nuxt 异步数据获取的作用,以及亲身体验了几个重要文件夹的意义,整篇文章 ...

  2. 《IDEO,设计改变一切》(Change By Design)- 读书笔记

    一.关于IDEO与设计思维 IDEO是一家世界顶级创意公司,而作者蒂姆布朗是IDEO的CEO.当然,在未阅读本书之前,我都是不知道的,也不会主动去了解IDEO和蒂姆布朗的.那么,我为什么要去读这样一本 ...

  3. 论AOP面向切面编程思想

    原创: eleven 原文:https://mp.weixin.qq.com/s/8klfhCkagOxlF1R0qfZsgg [前言] AOP(Aspect-Oriented Programming ...

  4. 18-09-20,String 与 StringBuilder (StringBuffer)

    1.其一 在运行速度方面:StringBuilder > StringBuffer > String 上实例 class Program { static void Main(string ...

  5. 在 DotNetCore 3.0 程序中使用通用协议方式启动文件关联应用

    问题描述 在传统的基于 .NET Framework 的 WPF 程序中,我们可以使用如下代码段启动相关的默认应用: # 启动默认文本编辑器打开 helloworld.txt Process.Star ...

  6. 002. https通信(CA证书认证 + 密钥商定 )

    服务端与客户端建立https通信的过程: 一.认证:客户端第一次访问服务端时,要求服务端证明自己可被信任 1.证书:由服务端申请.第三方CA颁发的,存放在服务端的证书: 证书包含:服务端的公钥.服务端 ...

  7. python网络爬虫-中国大学排名定向爬虫

    爬虫定向爬取中国大学排名信息 #!/usr/bin/python3 import requests from bs4 import BeautifulSoup import bs4 #从网络上获取大学 ...

  8. Vue与React两个框架的区别对比

    简单介绍 React--Facebook创建的JavaScript UI框架.它支撑着包括Instagram在内的大多数Facebook网站.React与当时流行的jQuery,Backbone.js ...

  9. findlibrary returned null

    转载请标明出处,维权必究:https://www.cnblogs.com/tangZH/p/10181330.html 该错误是在加载so库的时候出现的,就是找不到so库. 一.检查jinLibs目录 ...

  10. Hadoop 3.1.2(HA)+Zookeeper3.4.13+Hbase1.4.9(HA)+Hive2.3.4+Spark2.4.0(HA)高可用集群搭建

    目录 目录 1.前言 1.1.什么是 Hadoop? 1.1.1.什么是 YARN? 1.2.什么是 Zookeeper? 1.3.什么是 Hbase? 1.4.什么是 Hive 1.5.什么是 Sp ...