some additional bugfixes
This commit is contained in:
parent
6630078686
commit
833f1092d0
18
Logger.py
18
Logger.py
|
@ -38,16 +38,26 @@ class Logger():
|
|||
fsize = os.stat(logfilename)[6]
|
||||
iter = 0
|
||||
with open(logfilename, "r") as logfile:
|
||||
fetched_lines = []
|
||||
line_count = 0
|
||||
for line in logfile:
|
||||
line_count += 1
|
||||
if (lines > line_count):
|
||||
lines = line_count
|
||||
#todo if lines from todays logfile are less than the number of requested lines, read missing lines from yesterdays logfile - only if not tempLogFile!
|
||||
if bufsize > fsize:
|
||||
bufsize = fsize - 1
|
||||
fetched_lines = []
|
||||
while True:
|
||||
iter += 1
|
||||
logfile.seek(fsize - bufsize * iter)
|
||||
fetched_lines.extend(logfile.readlines())
|
||||
try:
|
||||
logfile.seek(fsize - bufsize * iter)
|
||||
fetched_lines.extend(logfile.readlines())
|
||||
except:
|
||||
return "eof"
|
||||
break
|
||||
if len(fetched_lines) >= lines or logfile.tell() == 0:
|
||||
#todo if lines from todays logfile are less than the number of requested lines, read missing lines from yesterdays logfile - only if not tempLogFile!
|
||||
return "<br>".join(fetched_lines[-lines:])
|
||||
break
|
||||
|
||||
def MergeTempLogfile(self):
|
||||
if not self.tempLogFile:
|
||||
|
|
14
main.py
14
main.py
|
@ -15,7 +15,7 @@ from secrets import secrets
|
|||
from configs import configs
|
||||
|
||||
rp2.country(configs['country'])
|
||||
version = "0.9-beta"
|
||||
version = "0.10-beta"
|
||||
|
||||
Oled = Oled.Oled()
|
||||
TimeUtils = TimeUtils.TimeUtils()
|
||||
|
@ -274,7 +274,7 @@ async def APIHandling(reader, writer):
|
|||
elif (req[2] == "ping"):
|
||||
stateis = "OK"
|
||||
elif (req[2] == "stats"):
|
||||
stateis = "IP address: " + Networking.GetIPAddress() + "<br>MAC address: " + Networking.GetMACAddress() + "<br>Hostname: " + configs['hostname'] + "<br>API Port: " + str(configs['api_port']) + "<br>Uptime (h:m): " + Uptime() + "<br>Date/Time: " + TimeUtils.DateTimeNow() + "<br>Version: " + version + "<br>GMT Timezone Offset (hours): " + str(configs['gmt_offset']) + "<br>Auto summertime: " + str(configs['auto_summertime']) + "<br>Display off time (mins): " + str(configs['displayoff']) + "<br>Log incoming bus messages: " + str(configs['log_incoming_bus_messages']) + "<br>Housekeep logfiles after days: " + str(configs['log_housekeeping_days']) + "<br>Message 'Front door ringing': " + str(configs['frontdoor_ringing_message']) + "<br>Message 'Door ringing': " + str(configs['door_ringing_message']) + "<br>Message 'Door opener triggered': " + str(configs['door_trigger_message']) + "<br>Message 'Light triggered': " + str(configs['light_trigger_message']) + "<br>CPU frequency (MHz): " + str(machine.freq()/1000000)
|
||||
stateis = "IP address: " + Networking.GetIPAddress() + "<br>MAC address: " + Networking.GetMACAddress() + "<br>Hostname: " + configs['hostname'] + "<br>API Port: " + str(configs['api_port']) + "<br>Uptime (h:m): " + Uptime() + "<br>Date/Time: " + TimeUtils.DateTimeNow() + "<br>Version: " + version + "<br>GMT Timezone Offset (hours): " + str(configs['gmt_offset']) + "<br>Auto summertime: " + str(configs['auto_summertime']) + "<br>Display off time (mins): " + str(configs['displayoff']) + "<br>Log incoming bus messages: " + str(configs['log_incoming_bus_messages']) + "<br>Housekeep logfiles after days: " + str(configs['log_housekeeping_days']) + "<br>Message 'Front door ringing': " + str(configs['frontdoor_ringing_message']) + "<br>Message 'Door ringing': " + str(configs['door_ringing_message']) + "<br>Message 'Door opener triggered': " + str(configs['door_trigger_message']) + "<br>Message 'Light triggered': " + str(configs['light_trigger_message']) + "<br>CPU frequency (MHz): " + str(machine.freq()/1000000) + "<br>Party-Mode is: " + PartyModeState()
|
||||
elif (req[2] == "reboot"):
|
||||
stateis = "Rebooting device now..."
|
||||
Reboot()
|
||||
|
@ -291,12 +291,20 @@ async def APIHandling(reader, writer):
|
|||
else:
|
||||
stateis = "<b>Error:</b> Parameter for log length not an integer!"
|
||||
else:
|
||||
stateis = Logger.LastLogs(50)
|
||||
stateis = Logger.LastLogs(12)
|
||||
else:
|
||||
stateis = "<b>Error:</b> Unknown command!"
|
||||
else:
|
||||
stateis = "<b>Error:</b> API key is invalid!"
|
||||
if ((len(req) == 4 and req[3] == "json") or (len(req) == 5 and req[4] == "json")):
|
||||
if (req[2] != "logs"):
|
||||
stateis = stateis.replace(": ", "\":\"")
|
||||
stateis = stateis.replace("<br>", "\", \"")
|
||||
stateis = stateis.replace("°", "°")
|
||||
else:
|
||||
stateis = stateis.replace(";", "\":\"")
|
||||
stateis = stateis.replace("<br>", "\", \"")
|
||||
stateis = stateis.replace("\n", "").replace("\r", "")
|
||||
response = json % stateis
|
||||
writer.write('HTTP/1.0 200 OK\r\nContent-type: text/json\r\n\r\n')
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue