You spend too much time in front of the computer
and you want to know how much, or maybe you simply want to know how long you have been working on something today. For either cases, I made this little script for linux, that you must launch at startup (put it in your startup apps list, or launch it manually). It will then record the time passed since you turned on your computer, and subtract the time your desktop was in screensaver mode, resulting in the time you were actually sitting doing something with the computer.
Of course it wont help you to know how long you have been working and how long you spent staring at facebook. But there are much better time-logging apps available on the net to solve that problem...
The script will store the current activity time in a ".activitytime" file inside your home folder, so you can just do "cat ~/.activitytime" from a terminal or from any other script (launcher, panel widget, etc...) to display your current activity time.
r = os.system("xprintidle")
if r != 0:
print "Error: xprintidle was not found, and must be installed for this program to run"
total_idle = 0
"returns uptime in minutes"
with open("/proc/uptime", "r") as f:
uptime_seconds = float(f.readline().split())
"returns idle time in minutes"
r = os.popen("xprintidle")
idle_minutes = int(r.read())/60000
if idle_minutes > 1:
total_idle += 1
"formats atime in minutes to HH:MM"
hours = minutes/60
restminutes = minutes%60
"writes current activity time to a file"
strtime = formattime(uptime() - idletime())
print ("active time: "+strtime)
fil = open(os.path.expanduser("~") + os.sep + ".activitytime","wb")
"reads a temp file and adjusts elapsed idle"
fpath = os.path.expanduser("~") + os.sep + ".activitytime"
fil = open(fpath,"r")
r = fil.read()
t = r.split(":")
minutes = int(t)*60 + int(t)
print "logged activity time: ",formattime(minutes)
print "current uptime: ",formattime(uptime())
total_idle = uptime() - minutes
print "logged idle time: ",formattime(total_idle)
if __name__ == "__main__":
if len(sys.argv) == 1:
# if no argument is given, start from zero
# with an argument, for ex --append, restart from currently saved time