minor fixes
This commit is contained in:
parent
d3a9e9affa
commit
1a38065a08
1 changed files with 16 additions and 15 deletions
|
@ -60,18 +60,18 @@ def tail(filepath):
|
||||||
"""
|
"""
|
||||||
Thanks: https://stackoverflow.com/a/41491521
|
Thanks: https://stackoverflow.com/a/41491521
|
||||||
"""
|
"""
|
||||||
with open(filepath, "rb") as f:
|
with open(filepath, "rb") as f:
|
||||||
first = f.readline() # Read the first line.
|
first = f.readline() # Read the first line.
|
||||||
f.seek(-2, 2) # Jump to the second last byte.
|
f.seek(-2, 2) # Jump to the second last byte.
|
||||||
while f.read(1) != b"\n": # Until EOL is found...
|
while f.read(1) != b"\n": # Until EOL is found...
|
||||||
try:
|
try:
|
||||||
f.seek(-2, 1) # ...jump back the read byte plus one more.
|
f.seek(-2, 1) # ...jump back the read byte plus one more.
|
||||||
except IOError:
|
except IOError:
|
||||||
f.seek(-1, 1)
|
f.seek(-1, 1)
|
||||||
if f.tell() == 0:
|
if f.tell() == 0:
|
||||||
break
|
break
|
||||||
last = f.readline() # Read last line.
|
last = f.readline() # Read last line.
|
||||||
return last
|
return last
|
||||||
|
|
||||||
# make sure log file exists
|
# make sure log file exists
|
||||||
if not os.path.exists(logfile):
|
if not os.path.exists(logfile):
|
||||||
|
@ -79,9 +79,10 @@ if not os.path.exists(logfile):
|
||||||
f.write("{},{},{}".format(time.time(), 0,0))
|
f.write("{},{},{}".format(time.time(), 0,0))
|
||||||
|
|
||||||
# get last line of log file and update 'total use' using that.
|
# get last line of log file and update 'total use' using that.
|
||||||
last = tail("")
|
last = tail(logfile)
|
||||||
bits = last.split(",")
|
bits = last.split(",")
|
||||||
totalUse = bits[2]
|
totalUse = float(bits[2])
|
||||||
|
print "Total use:", totalUse
|
||||||
|
|
||||||
log = open(logfile, "a")
|
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("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)))
|
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()
|
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()
|
content = urllib2.urlopen("https://artstats.rubenvandeven.com/artwork1/views.php?time=%d&count=%d&total=%d" % (int(time.time()), len(faces), int(totalUse)) ).read()
|
||||||
|
|
Loading…
Reference in a new issue