I'm working on a project with python in a raspberry pi.
I have a log file that is continuously logging time and at a specific second a command is sent to it (a Shed command from a water heater.)
I'm trying to write a code that reads the last line in that log file and turn off GPIO X when a shed command is sent (and does nothing when last line is just a time-stamp).
Here is an algorithm to make it clear:
- Read log file
- if last line is shed command: turn off GPIO X
----else: do nothing
I tried one method but it does not read the last line, it reads every line and goes back to the first when it reaches the last line. I only want to read the last line.
Here is a code I tried:
import time
fileHandle = open ('UCM.log')
lineList = fileHandle.readlines()
fileHandle.close()
while True:
#for line in (open(UCM.log).readlines()):
if " Sending Application message: Shed" in lineList[len(lineList)-1]:
time.sleep
print 'Shed!'