python read dir files and find key words

#!/usr/bin/env python

coding:utf-8

import os
import re

filelist=[]
#path = “/Volumes/C/work/veridian/issue/SMP_LAN_DOE/8-3A/”
#path = “/Volumes/C/work/veridian/SPC_calibration/data/”
path = “/Volumes/C/work/6x/issue/cc_acc/nvt_oqc_repeatdata/”
dict = {}
unitID = []
temperature = []
ggTemperature = []
passfail = []
flow = “”
unitID1 = 0
temperature1 = 0
ggTemperature1 = 0
testTime = 0
testflag = “”
filesummay = open(‘issue_report.txt’, ‘w’)
filesummay.write(‘carrierID’)
filesummay.write(’\t’)
filesummay.write(‘SN’)
filesummay.write(’\t’)
filesummay.write(str(‘gg_cc_dsg’))
filesummay.write(’\t’)
filesummay.write(str(‘tester_cc_dsg’))
filesummay.write(’\t’)
filesummay.write(‘test current’)
filesummay.write(’\t’)
filesummay.write(‘gg current’)
filesummay.write(’\t’)
filesummay.write(‘file’)
filesummay.write(’\n’)
errCode = ‘’

for root, dirs, files in os.walk(path):
for name in files:
#print(dir, name)
if name.endswith(".log"):
f=open(os.path.join(root,name),‘r’, encoding=‘gbk’)
filename=(os.path.join(root, name))
#print(filename)
data=f.read()
else:
continue # skip this file
testflag = “Pass”
# temperature1=0
# temperature1=0
# match = re.search(“created unit [ ([A-Z0-9]+) ]”, data, re.MULTILINE)
# if match:
# unitID.append(match.group(1))
# unitID1= match.group(1)
# else:
# unitID1=""
match = re.search(r"tester ID : [ ([A-Z0-9]+) ]", data, re.MULTILINE)
if match:
unitID.append(match.group(1))
unitID1 = match.group(1)
# print(unitID1)
else:
unitID1 = “”
‘’’ flowID
match = re.search(r"flow is:[ (\d+) ]", data, re.MULTILINE)
if match:
# unitID.append(match.group(1))
flow = match.group(1)
#print(flow)
else:
flow = “”
# Voltage b = [
‘’’
# Serial Number
match = re.search(r"Serial Number =(\w+)", data, re.MULTILINE)
if match:
# unitID.append(match.group(1))
SerialNo = match.group(1)
# print(SerialNo)
else:
SerialNo = “”

    # Voltage b = [

#1s gg current = [ -0.500175 ]A
match = re.search(r"1s gg current = [ (-\d+.\d+) ]", data, re.MULTILINE)
if match:
# temperature.append(match.group(1))
dsg_gg = match.group(1)
print(dsg_gg)
else:
dsg_gg = ‘’
# tester read current
match = re.search(
r"tester read curent = [ ((-)?\d+.\d+)",
data,
re.MULTILINE)
if match:
ggTemperature1 = match.group(1)
# ggTemperature.append(match.group(1))
# ggTemperature1 = match.group(2)
else:
ggTemperature1 = ‘’
match = re.search(r"tester read curent = [ ((-)?\d+.\d+)", data, re.MULTILINE)
#match = re.search(r"tester cell voltage = [ ((-)?\d+.\d+)", data, re.MULTILINE)
if match:
# passfail.append(match.group(0))
test_cell = match.group(1)
print(test_cell)
# match = re.search(r"test key [(\w+)",data, re.MULTILINE)
#test_cell = match.group(1)
#print(errCode)
else:
test_cell=""
#match = re.search(r"oqc_ocv_shipping ] | Lower spec [ 0.000000 ] | measurement [ ((-)?\d+.\d+)", data, re.MULTILINE)
match = re.search(r"1s gg current = [ (-\d+.\d+)", data, re.MULTILINE)
if match:
#test_cell = match.group(1)
#print(test_cell)
# passfail.append(match.group(0))
#testflag = “Error”
# match = re.search(r"test key [(\w+)",data, re.MULTILINE)
test_pack = match.group(1)
# print(test_pack)
else:
test_pack=""

    filesummay.write(str(unitID1))
    filesummay.write('\t')
    filesummay.write(str(flow))
    filesummay.write('\t')
    filesummay.write(str(dsg_gg))
    filesummay.write('\t')
    filesummay.write(str(ggTemperature1))
    filesummay.write('\t')
    filesummay.write(test_cell)
    filesummay.write('\t')
    filesummay.write(test_pack)
    filesummay.write('\t')
    filesummay.write(filename)
    filesummay.write('\n')
    errCode = ''

filesummay.close()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值