工作中给同事写的便捷统计小程序

1,测试一千次开关机,几个阶段的时间

# coding:utf-8
import os
from datetime import datetime


def get_txts(file_path):
    files = os.listdir(file_path)

    for file in files:
        with open(os.path.join(file_path, file), "r", encoding="UTF-8") as f:
            for txt in f:
                if 'start power on' in txt:
                    t1 = txt[0:19].replace('_', '-')
                    t11 = txt
                    t111 = datetime.strptime(t1, '%Y-%m-%d %H:%M:%S').timestamp()
                if 'vinput: window position has been updated to: [0,0]' in txt:
                    t2 = txt[0:19].replace('_', '-')
                    t22 = txt
                    t222 = datetime.strptime(t2, '%Y-%m-%d %H:%M:%S').timestamp()
                if 'Startup complete' in txt:
                    t3 = txt[0:19].replace('_', '-')
                    t33 = txt
                    t333 = datetime.strptime(t3, '%Y-%m-%d %H:%M:%S').timestamp()

                    print(t222 - t111, '|', t333 - t111)

                    if t222 - t111 > 15 or t333 - t111 > 50:
                        print('file = ', file)

get_txts(r'E:\Work\space\raspberry_log\logdate\常温(1)\常温\log')
View Code

 

posted @ 2024-01-17 18:51  夜未央leo  阅读(3)  评论(0编辑  收藏  举报