minor fixes

This commit is contained in:
Artwork1 2018-01-04 23:46:40 +01:00
parent d3a9e9affa
commit 1a38065a08

View file

@ -60,18 +60,18 @@ def tail(filepath):
"""
Thanks: https://stackoverflow.com/a/41491521
"""
with open(filepath, "rb") as f:
first = f.readline() # Read the first line.
f.seek(-2, 2) # Jump to the second last byte.
while f.read(1) != b"\n": # Until EOL is found...
try:
f.seek(-2, 1) # ...jump back the read byte plus one more.
except IOError:
f.seek(-1, 1)
if f.tell() == 0:
break
last = f.readline() # Read last line.
return last
with open(filepath, "rb") as f:
first = f.readline() # Read the first line.
f.seek(-2, 2) # Jump to the second last byte.
while f.read(1) != b"\n": # Until EOL is found...
try:
f.seek(-2, 1) # ...jump back the read byte plus one more.
except IOError:
f.seek(-1, 1)
if f.tell() == 0:
break
last = f.readline() # Read last line.
return last
# make sure log file exists
if not os.path.exists(logfile):
@ -79,9 +79,10 @@ if not os.path.exists(logfile):
f.write("{},{},{}".format(time.time(), 0,0))
# get last line of log file and update 'total use' using that.
last = tail("")
last = tail(logfile)
bits = last.split(",")
totalUse = bits[2]
totalUse = float(bits[2])
print "Total use:", totalUse
log = open(logfile, "a")
@ -111,7 +112,7 @@ while True:
#~ lcd.message("viewers {:>8}\nview-min. {:>7.2f}".format(len(faces), totalUse/60))
lcd.message("{:>7} viewers \n{:>7}view-sec".format(len(faces), si_format(totalUse,precision=1)))
log.write("{},{},{}".format(time.time(), len(faces), int(totalUse)))
log.write("{},{},{}\n".format(time.time(), len(faces), int(totalUse)))
log.flush()
content = urllib2.urlopen("https://artstats.rubenvandeven.com/artwork1/views.php?time=%d&count=%d&total=%d" % (int(time.time()), len(faces), int(totalUse)) ).read()