import re
def read_log(filePath):
log = {}
timeList = []
contentList = []
lastTime = None
timeReg = r'((([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})\/(((0[13578]|1[02])\/(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)\/(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29))\s+([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])'
pattern = re.compile(timeReg)
with open(filePath, 'r', encoding='utf-8') as f:
lines = f.readlines()
for line in lines:
contentList.append(line)
res = re.search(pattern, line)
if res:
currentTime = res.group()
if lastTime is None:
lastTime = currentTime
if lastTime != currentTime and lastTime is not None:
contentList.pop()
log[lastTime] = contentList
contentList.clear()
contentList.append(line)
lastTime = currentTime
print('-------------')
print(log)
if __name__ == '__main__':
filePath = 'G:\EMA_v2\TerminalMessage\TerminalMessage.log-20221109-1.log'
read_log(filePath)
# res = {
# '2022/11/09 04:01:56':
# [
# "2022/11/09 13:17:12.922 The Command Completed Didn't Respond Within[180]Seconds.(13:15~13:12)\n",
# '请工程值班处理,Robot在[180]秒内,未及时回复动作结果给CPC,检查Robot状况\n',
# '若发生莫停,需手动切换CPC的Auto/Manual Mode [Repeat 5]\n',
# '2022/11/09 13:17:12.922 Robot Action1 Command Result Is NG\n',
# '2022/11/09 13:17:12.922 ANMOR100 Robot做动失败,确认Robot状况后做原点复归\n'],
# '2022/11/09 13:15:12':
# [
# "2022/11/09 13:17:12.922 The Command Completed Didn't Respond Within[180]Seconds.(13:15~13:12)\n",
# '请工程值班处理,Robot在[180]秒内,未及时回复动作结果给CPC,检查Robot状况\n',
# '若发生莫停,需手动切换CPC的Auto/Manual Mode [Repeat 5]\n',
# '2022/11/09 13:17:12.922 Robot Action1 Command Result Is NG\n',
# '2022/11/09 13:17:12.922 ANMOR100 Robot做动失败,确认Robot状况后做原点复归\n']
# }
2022/11/09 04:01:56.533 [S2F21] Port [1] 被Host退卡 : Host Cancel : AUOpVerify NG[TE36408]:Equipment doe not match with equipment capability.
2022/11/09 13:15:12.266 The Command Completed Didn't Respond Within[180]Seconds.(13:15~13:12)
2022/11/09 13:15:12.266 请工程值班处理,Robot在[180]秒内,未及时回复动作结果给CPC,检查Robot状况
2022/11/09 13:15:12.266 若发生莫停,需手动切换CPC的Auto/Manual Mode
2022/11/09 13:17:12.922 The Command Completed Didn't Respond Within[180]Seconds.(13:15~13:12)
请工程值班处理,Robot在[180]秒内,未及时回复动作结果给CPC,检查Robot状况
若发生莫停,需手动切换CPC的Auto/Manual Mode [Repeat 5]
2022/11/09 13:17:12.922 Robot Action1 Command Result Is NG
2022/11/09 13:17:12.922 ANMOR100 Robot做动失败,确认Robot状况后做原点复归
标签:11,13,09,cpc,12.922,Robot,auo,2022
From: https://www.cnblogs.com/zhuoss/p/16881608.html