当前位置:网站首页>Use py to automatically generate weekly reports based on log records
Use py to automatically generate weekly reports based on log records
2022-07-28 16:06:00 【51CTO】
The format of the log is as follows , The idea is if it detects that the content in the file is 5 Bits or 8 position , namely 12.11 or 18.12.11, At the same time . That is, the date data of the current behavior
Just for the convenience of viewing the log , Filter this line when generating the script . Each time a blank line is read, the next record is considered to be the record of the new day ,
In addition, if you read ==== It's the end of the week , You can generate and exit scripts
12.21
Remaining life list
12.20
Monitor the tool change record
===============================================
===============================================
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
Script
# -*- 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# Serial number
newDay=1# Is it another day's record
f=open(r"C:\Users\Dell\Desktop\a.txt")
i=4# Line number
hour=6# Working hours
context=0
ids=1
thing=2# Work items
project=3# Project
skill=4# Technical point decomposition description
other=5# Need to coordinate content ( Multi person interface joint debugging 、 Field test 、 Customer trial and so on )
planStart=7# Plan to start
planEnd=8# Plan end time
start=9# Time start time
end=10# Time, finish time
statu=11# Completion status
backup=12# Summary and record
# style
borders = xlwt.Borders() # Create borders
borders.left = xlwt.Borders.THIN # Add border - Dotted border
borders.right = xlwt.Borders.THIN # Add border - Dotted border
borders.top = xlwt.Borders.THIN # Add border - Dotted border
borders.bottom = xlwt.Borders.THIN # Add border - Dotted border
borders.left_colour = 0x08 # Color the border
borders.right_colour = 0x08
borders.top_colour = 0x08
borders.bottom_colour = 0x08
# Column width
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
# Create a style ----------------------------
stylefirstRow = xlwt.XFStyle()
stylefirstRow.borders = borders
pattern = xlwt.Pattern()
pattern.pattern =xlwt. Pattern.SOLID_PATTERN
pattern.pattern_fore_colour = xlwt.Style.colour_map['gold']
# Set the cell background color to yellow
stylefirstRow.pattern = pattern
al = xlwt.Alignment()
al.horz = 0x02 # Set horizontal center
al.vert = 0x01 # Set vertical center
al.wrap=1 # Word wrap
stylefirstRow.alignment = al
font = xlwt.Font() # Create fonts for styles
#font.name = 'Times New Roman'
font.name = u' Microsoft YaHei '
#font.bold = True # In black
#font.underline = True # Underline
#font.italic = True # italics
font.height=0x00C8*1.6 # C8 in Hex (in decimal) = 10 points in height.
#font.colour_index=48# Blue
#font.colour_index=2# Red
#font.colour_index=59# gray
#font.colour_index=44# The light blue
stylefirstRow.font = font # Set style
# The second line style ----------------------------
stylesecondRow = xlwt.XFStyle()
stylesecondRow.borders = borders
font2 = xlwt.Font() # Create fonts for styles
font2.name = u' Microsoft YaHei '
font2.height=0x00C8*1.4 # C8 in Hex (in decimal) = 10 points in height.
stylesecondRow.font = font2 # Set style
stylesecondRow.alignment = al
# The first 3 Row style ----------------------------
style3Row = xlwt.XFStyle()
style3Row.borders = borders
font3 = xlwt.Font() # Create fonts for styles
font3.name = u' Microsoft YaHei '
font3.height=0x00C8 # C8 in Hex (in decimal) = 10 points in height.
font3.colour_index=48# Blue
style3Row.font = font3 # Set style
#style3Row.alignment = al
# Unified font
fontx = xlwt.Font() # Create fonts for styles
fontx.name = u' Microsoft YaHei '
fontx.height=0x00C8*1.2 # C8 in Hex (in decimal) = 10 points in height.
# Grey background
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
# Light green background
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
# Green background
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
# Set cell background color
styleGreenRow.pattern = patternGreen
styleGreenRow.alignment = al
# Red character
redstyle = xlwt.XFStyle()
redstyle.borders = borders
fontred= xlwt.Font() # Create fonts for styles
fontred.name = u' Microsoft YaHei '
fontred.height=0x00C8*1.2 # C8 in Hex (in decimal) = 10 points in height.
fontred.colour_index=2# Red
redstyle.font=fontred
redstyle.pattern=patternGray
redstyle.alignment = al
# Universal style
styleCommon = xlwt.XFStyle()
styleCommon.borders = borders
styleCommon.font=fontx
styleCommon.alignment = al
# Template content
worksheet.write_merge(0, 0,0,12, label = " Weekly work report of product development department ",style=stylefirstRow)
worksheet.write_merge(1, 1,5,7, label = " Zhang San ",style=stylesecondRow)
worksheet.write_merge(2, 2,0,12, label = " notes : Make a summary of this week's work every Friday ( Turn off the watch ), At the same time, make next week's work plan ( Open a watch ), Adjust next Monday if necessary ;",style=style3Row)
worksheet.write(3, context, label = " Content ",style=styleGrayRow)
worksheet.write(3, ids, label = " Serial number ",style=styleGrayRow)
worksheet.write(3, thing, label = " Work items ",style=styleGrayRow)
worksheet.write(3, project, label = " Project ",style=styleGrayRow)
worksheet.write(3, skill, label = " Technical point decomposition description ",style=styleGrayRow)
worksheet.write(3, other, label = " Need to coordinate content ( Multi person interface joint debugging 、 Field test 、 Customer trial and so on )",style=redstyle)
worksheet.write(3, hour, label = " Work time ",style=styleGrayRow)
worksheet.write(3, planStart, label = " Plan to start ",style=styleGrayRow)
worksheet.write(3, planEnd, label = " Plan end time ",style=styleGrayRow)
worksheet.write(3, start, label = " Actual start time ",style=styleGreenRow)
worksheet.write(3, end, label = " Actual start time ",style=styleGreenRow)
worksheet.write(3, statu, label = " Completion status ",style=styleGreenRow)
worksheet.write(3, backup, label = " Summary and record ",style=styleGreenRow )
for line in f:
line=line.replace('\n','')
# If the behavior space obtained last time , The date of the current action , Just skip
if newDay==1:
newDay=0
# Search for ## It's the end of the week
if line.find("====")!=-1:
break
else:
#print strTime
# If the acquired content is a space, a new day's data will be started
if line=="":
# Update the current date
newDay=1
now=now+datetime.timedelta(days=-1)
else:
newDay=0# Set to non new day data
# 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 = "9",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 = " complete ",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 = " Summary of this week's work ",style=styleLightGreenRow)
f.close()
workbook.save(r"C:\Users\Dell\Desktop\\"+" Product development weekly _ Zhang San _".decode('utf-8').encode('cp936')+datetime.datetime.now().strftime("%Y_%m_%d")+".xlsx")
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
- 111.
- 112.
- 113.
- 114.
- 115.
- 116.
- 117.
- 118.
- 119.
- 120.
- 121.
- 122.
- 123.
- 124.
- 125.
- 126.
- 127.
- 128.
- 129.
- 130.
- 131.
- 132.
- 133.
- 134.
- 135.
- 136.
- 137.
- 138.
- 139.
- 140.
- 141.
- 142.
- 143.
- 144.
- 145.
- 146.
- 147.
- 148.
- 149.
- 150.
- 151.
- 152.
- 153.
- 154.
- 155.
- 156.
- 157.
- 158.
- 159.
- 160.
- 161.
- 162.
- 163.
- 164.
- 165.
- 166.
- 167.
- 168.
- 169.
- 170.
- 171.
- 172.
- 173.
- 174.
- 175.
- 176.
- 177.
- 178.
- 179.
- 180.
- 181.
- 182.
- 183.
- 184.
- 185.
- 186.
- 187.
- 188.
- 189.
- 190.
- 191.
- 192.
- 193.
- 194.
- 195.
- 196.
- 197.
- 198.
- 199.
- 200.
- 201.
- 202.
- 203.
- 204.
- 205.
- 206.
- 207.
边栏推荐
- Software architecture and design (II) -- Architecture Model
- What are the process specifications of software testing? How to do it?
- 正大杯黑客马拉松数据解析竞赛
- 高速计数器转RS485Modbus RTU模块IBF150
- Advantages of optical rain gauge over tipping bucket rain gauge
- Software architecture and design (VII) -- interactive architecture
- 12V pulse speed measurement to 24V level signal conversion transmitter
- 管理区解耦架构见过吗?能帮客户搞定大难题的
- js 数组(总结)
- 跳表的实现
猜你喜欢

高精度绝对角度传感器应用高速度角度监测

High speed counter to rs485modbus RTU module ibf150

JS queue

Duty cycle switch output high speed pulse counter rtumodbus module ibf63

光学雨量计应用降雨量检测

Rust 入门指南(crate 管理)

管理区解耦架构见过吗?能帮客户搞定大难题的

5-channel di/do relay output remote IO acquisition module Modbus tcp/ibf95

Instructions for mictr01 Tester development kit (vibrating wire acquisition reader)

Vm501 development kit development version single vibrating wire sensor acquisition module geotechnical engineering monitoring
随机推荐
Remember the common JS methods of projects
光学雨量计应用降雨量检测
占空比开关量输出高速脉冲计数器RTUModbus模块IBF63
Docker implements redis cluster mode hash slot partition for 100 million level data storage
使用py,根据日志记录自动生成周报
[wechat applet development (VII)] subscription message
Rust Getting Started Guide (crite Management)
编码器高速脉冲计数器Modbus RTU模块IBF150
Transformation principle of voltage and frequency
Two special functions (arrow function and method)
MicTR01 Tester 开发套件(振弦采集读数仪)使用说明
分体式测斜探头安装要点及注意事项
Rust 入门指南(crate 管理)
Connection and application of portable borehole inclinometer data acquisition instrument and inclinometer probe
热敏电阻PT100,NTC转0-10V/4-20mA转换器
[channel attention mechanism] senet
2.855 billion yuan! Qingdao Xinen completed the capital increase: Xingcheng Jidian became the largest shareholder, holding 57.10%
Principle and application of low cost / small volume module rs485/232 to analog signal ibf33
食品安全 | 这两类瓜果宜改善便秘 孕妇人群尤其建议
2021 Kent interview question 1