使用python重写上篇文章的内容分析工具

import sys
import re
import time


def readfile():
    information = []
    count = 0
    count1 = 0
    fileDir = "c:/test.log"


    #需要找到的关键字符串1
    findString = "保存需求上报流程数据"
    #需要找到的关键字符串2
    findString1 = "计通[2015]66号《关于下发《基于全过程的管线资源建设管理要求》的通知》"


    #遍历出一个大数组出来
    for line in open(fileDir, encoding = 'gb2312'):
        pattern = re.compile('[2]\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d')
        match = pattern.match(line)


        #如果找到了时间戳
        if match:
            count1 +=1
            date = match.group()
            item = [date,line]
            information.append(item)
        else:
            information[len(information)-1][1] = information[len(information)-1][1] + line
            
        count += 1


    #下面开始找字符串
    resultCount = 0
    for a in information:
        if boolFindTxt(a[1], findString):
            if boolFindTxt(a[1],findString1):
                print(a[1])
                resultCount += 1
            
                
    print ("line total:",count)
    print ("Time stamp matched ",count1)
    print ("result line total: ", resultCount)


#从一个字符串中找到txt
def boolFindTxt(line, txt):
    result = line.find(txt)
    if result == -1:
        return False
    else:
        return True


start = time.clock()    
readfile()
end = time.clock()


print ("read:{} s".format(end -start))
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值