当前位置:网站首页>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.
边栏推荐
- NTC,PT100热电阻转4-20mA温度信号转换器
- What is the concept of game testing? What are the test methods and processes?
- 电压频率的变换原理
- A wave of operation to solve the error problem of Laya scene editor
- 光学雨量计应用降雨量检测
- 兆骑科创创业大赛平台,活动路演,投融资对接
- JS array (summary)
- R language ggplot2 visually draws line plots, and uses gghighlight package to highlight the lines that meet the combination judgment conditions in the line graphs (satisfies both condition a and b)
- 2.855 billion yuan! Qingdao Xinen completed the capital increase: Xingcheng Jidian became the largest shareholder, holding 57.10%
- 0-75mv/0-100mv to rs485/232 communication interface Modbus RTU acquisition module ibf8
猜你喜欢

IFD-x 微型红外成像仪(模块)的温度测量和成像精度

One channel encoder, two channels Di speed measurement, RS485 serial port connected to one channel do alarm module ibf151

2021 亚鸿笔试题2

Laser rangefinder non-contact surface crack monitor

Rust Getting Started Guide (crite Management)

JS priority queue

2021 Yahong pen test question 2

2021 肯特面试题3

JS bidirectional linked list 01

The deep displacement monitoring system wk813 is used to measure the deep displacement of slopes, dams, embankments, railways and building foundation pit excavation
随机推荐
Application of optical rain gauge to rainfall detection
【直播预约】数据架构演进下的新挑战——上海站
The deep displacement monitoring system wk813 is used to measure the deep displacement of slopes, dams, embankments, railways and building foundation pit excavation
A wave of operation to solve the error problem of Laya scene editor
IFD-x 微型红外成像仪(模块)的温度测量和成像精度
Transformation principle of voltage and frequency
Software architecture and design (I) -- key principles
2021 Yahong pen test question 2
Laser rangefinder non-contact surface crack monitor
太阳能路灯的根本结构及作业原理
开光量输入/继电器输出rs485/232远程数据采集IO模块IBF70
js中的for循环总结
R语言ggplot2可视化绘制线图(line plot)、使用gghighlight包突出高亮线图中满足组合判断条件的线图(satisfies both condition A and B)
Pyqt5 rapid development and practice 5.2 container: load more controls
A failed cracking experience
电压转电流/电流转电压模块
JS linked list 01
Advantages of optical rain gauge over tipping bucket rain gauge
Software architecture and design (IX) -- component based architecture
12V脉冲转速测量转24V电平信号转换变送器