自動生成日報表

此處用到兩個python腳本:

data.py

from datetime import datetime

filename='record20180907.txt'
x1,x2,x3,x4,x5,x6=[],[],[],[],[],[]
with open(filename,'r') as f:
	lines=f.readlines()
	for line in lines:
		value=line.strip().split()
		x1.append(value[0])  #data
		x2.append(value[1])  
		x3.append(value[3])  #source
		x4.append(value[23])  #engneer
		
		x5.append(value[4])
		x6.append(value[5])

x33=x3[0]
x55=x5[0]
x66=x6[0]

#print x1,x2,x3
d=x1[0]

n1=x4[1]
n2=[n1]
for i in x4:
	if i==n1:
		continue
	else:
		n1=i
		n2.append(i)

#delete chong fu source and time

s1=x3[0]
tr1=x2[0]
s2=[s1]
tr2=[tr1]
tr22=[]
for i in range(len(x3)):
	if x3[i]==s1:
		continue
	else:
		s1=x3[i]
		s2.append(x3[i])
		tr2.append(x2[i])
		tr22.append(x2[i])
 
#print s2,tr2,tr22
s0='STOP'
Trr=[]
for i in range(len(s2)):
	if s2[i]==s0:
		trr=tr2[i]+'-'+tr22[i]
		Trr.append(trr)
	else:
		continue
print Trr

#############################################################

filename='slrecord20180907.asc'
x11,x13=[],[]
with open(filename,'r') as f:
	lines=f.readlines()
	for line in lines:
		value=line.strip().split()
		x11.append(value[0])
		x13.append(value[2])
#print len(x11),len(x13)

k1=x13[0]
t1=x11[0]
k2=[k1]
t2=[t1]
#print k1,t1,t2,k2
#delete chong fu data
for i in range(len(x13)):
	if x13[i]==k1:
		continue
	else:
		k1=x13[i]
		k2.append(x13[i])
		t2.append(x11[i])
#print k2,t2

T2=t2
#print T2
T1=[]
for i in range(len(t2)):
	if i==0:
		continue
	else:
		T1.append(t2[i])
T1.append(' ')
#print T1
#len2=len(T2)
#len1=len(T1)
#print len1,len2

K3=k2
#print K
T3=[]
for i in range(len(T1)):
		TT=T2[i]+'-'+T1[i]
		T3.append(TT)
#print T3
#l=len(T3)
#print l

#shu chu T3\K3

#############################
#ke ti time and name
b='BZY'
tk1=T3[0]
kk1=K3[0]
tk2=[tk1]
kk2=[kk1]
for i in range(len(K3)):
	if K3[i]!=b:
		if K3[i]==kk1:
			continue
		else:
			kk1=K3[i]
			tk2.append(T3[i])
			kk2.append(K3[i])
	else:
		continue
print tk2,kk2

#BZY time and name
b='BZY'
tb=[]
for i in range(len(K3)):
	if K3[i]!=b:
			continue
	else:
		tb.append(T3[i])
print tb


2.py

#coding=utf-8
import docx
from docx.enum.text import WD_ALIGN_PARAGRAPH
import data

doc=docx.Document()
#doc.add_heading(u'青海觀測站13.7m日報表',level=2)
paragraph=doc.add_paragraph(u'青海觀測站13.7米望遠鏡運行狀況日報表')
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER


table1=doc.add_table(rows=2,cols=1,style='Table Grid')
v1=data.d
v1=str(v1)
hdr_cells=table1.rows[0].cells
hdr_cells[0].text=u'時間:'+v1
hdr_cells=table1.rows[1].cells
hdr_cells[0].text=u'望遠鏡名稱:13.7米毫米波射電望遠鏡'
#row_cells=table.add_row().cells  #tian jia yi hang

table2=doc.add_table(rows=2,cols=2,style='Table Grid')  #tian jia table
hdr_cells=table2.rows[0].cells
hdr_cells[0].text=u'基地總值班:巨秉剛'
hdr_cells[1].text=u'觀測助手:巨秉剛 孫繼先 逯登榮 王敏'
hdr_cells=table2.rows[1].cells
hdr_cells[0].text=u'開機時間:00:00-24:00'
hdr_cells[1].text=u'關機時間:00:00-00:00'

table3=doc.add_table(rows=7,cols=1,style='Table Grid')
v3=data.n2
v30=v3[0]
v30=str(v30)
#v20.append(' ')
v31=v3[1]
v32=v3[2]
#v2=str(v2)
hdr_cells=table3.rows[0].cells
hdr_cells[0].text=u'值班人員:'+v30+'  '+v31+'  '+v32
hdr_cells=table3.rows[1].cells
hdr_cells[0].text=u'天氣狀況:'
hdr_cells=table3.rows[2].cells
hdr_cells[0].text=u'運行環境狀況:正常'
hdr_cells=table3.rows[3].cells
hdr_cells[0].text=u'設備運行狀況:正常'
hdr_cells=table3.rows[4].cells
hdr_cells[0].text=u'觀測課題名稱:'
hdr_cells=table3.rows[5].cells
hdr_cells[0].text=u'課題負責人:'
hdr_cells=table3.rows[6].cells
hdr_cells[0].text=u'有效觀測時間:'

table4=doc.add_table(rows=5,cols=6,style='Table Grid')  
v41=data.x33
v42=data.x55
v43=data.x66
v41=str(v41)
v42=str(v42)
v43=str(v43)
hdr_cells=table4.rows[0].cells  #huo qu line 0 suo you dan yuan ge
hdr_cells[0].text='Source'
hdr_cells[1].text='R.A.'
hdr_cells[2].text='Dec.'
hdr_cells[3].text='Source'
hdr_cells[4].text='R.A.'
hdr_cells[5].text='Dec.'
hdr_cells=table4.rows[1].cells
hdr_cells[0].text=v41
hdr_cells[1].text=v42
hdr_cells[2].text=v43
#hdr_cells=table4.rows[1].cells

table5=doc.add_table(rows=1,cols=1,style='Table Grid')
#table5.Cell(1,1).Select()
hdr_cells=table5.rows[0].cells
hdr_cells[0].text=u'獲取資料質量評估:'

table6=doc.add_table(rows=2,cols=3,style='Table Grid')
hdr_cells=table6.rows[0].cells
hdr_cells[0].text='R.M.S'
hdr_cells[1].text='TA'
hdr_cells[2].text='VEL'
hdr_cells=table6.rows[1].cells
hdr_cells[0].text=u''
hdr_cells[1].text=u''
hdr_cells[2].text=u'優'

table7=doc.add_table(rows=5,cols=1,style='Table Grid')
v71=data.tk2 #mei ge ke ti hao kai shi shi jian 
v71=str(v71)
v72=data.kk2 #mei ge ke ti ming chen
v72=str(v72)
v73=data.tb #BZY kai shi and jie shu shi jian 
v73=str(v73)
v74=data.Trr
v74=str(v74)
#v2=str(v2)
hdr_cells=table7.rows[0].cells
hdr_cells[0].text=u'故障描述:'
hdr_cells=table7.rows[1].cells
hdr_cells[0].text=u'故障發生時間:'
hdr_cells=table7.rows[2].cells
hdr_cells[0].text=u'故障排除措施:'
hdr_cells=table7.rows[3].cells
hdr_cells[0].text=u'維修人員:'
hdr_cells=table7.rows[4].cells
hdr_cells[0].text=u'開展的主要工作:\n (1)課題觀測時間段:'+'\n'+'       '+v71+';\n'+u'對應的課題號:'+'\n'+'       '+v72+';'+\
'\n(2)'+u'BZY觀測時間段:'+'\n'+v73+';'\
'\n(3)'+'\n'+v74+u',天氣差,暫停觀測;'



doc.save('2.docx')

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章