fixed log reading at first boot

This commit is contained in:
Simone Margaritelli 2019-09-27 16:38:20 +02:00
parent 0cf80ee8d5
commit 44a912d616

View File

@ -2,6 +2,7 @@ import os
import hashlib import hashlib
import time import time
import re import re
import os
from datetime import datetime from datetime import datetime
from pwnagotchi.mesh.peer import Peer from pwnagotchi.mesh.peer import Peer
@ -129,7 +130,7 @@ class SessionParser(object):
self.duration_human.append('%d seconds' % secs) self.duration_human.append('%d seconds' % secs)
self.duration_human = ', '.join(self.duration_human) self.duration_human = ', '.join(self.duration_human)
self.avg_reward /= self.epochs self.avg_reward /= (self.epochs if self.epochs else 1)
def __init__(self, path='/var/log/pwnagotchi.log'): def __init__(self, path='/var/log/pwnagotchi.log'):
self.path = path self.path = path
@ -147,15 +148,17 @@ class SessionParser(object):
'detected unit (.+)@(.+) \(v.+\) on channel \d+ \(([\d\-]+) dBm\) \[sid:(.+) pwnd_tot:(\d+) uptime:(\d+)\]') 'detected unit (.+)@(.+) \(v.+\) on channel \d+ \(([\d\-]+) dBm\) \[sid:(.+) pwnd_tot:(\d+) uptime:(\d+)\]')
lines = [] lines = []
with FileReadBackwards(self.path, encoding="utf-8") as fp:
for line in fp: if os.path.exists(self.path):
line = line.strip() with FileReadBackwards(self.path, encoding="utf-8") as fp:
if line != "" and line[0] != '[': for line in fp:
continue line = line.strip()
lines.append(line) if line != "" and line[0] != '[':
if SessionParser.START_TOKEN in line: continue
break lines.append(line)
lines.reverse() if SessionParser.START_TOKEN in line:
break
lines.reverse()
self.last_session = lines self.last_session = lines
self.last_session_id = hashlib.md5(lines[0].encode()).hexdigest() self.last_session_id = hashlib.md5(lines[0].encode()).hexdigest()