Categories:
-
3d 96 articles
-
animations 16 articles
-
architecture 47 articles
-
blender 98 articles
-
bédé 19 articles
-
techdrawing 24 articles
-
freecad 189 articles
-
gaming 1 articles
-
idsampa 8 articles
-
inthepress 8 articles
-
linux 57 articles
-
music 1 articles
-
nativeifc 30 articles
-
opensource 266 articles
-
orange 4 articles
-
photo 16 articles
-
projects 35 articles
-
receitas 176 articles
-
saopaulo 18 articles
-
sketches 163 articles
-
talks 25 articles
-
techdrawing 24 articles
-
textes 7 articles
-
trilhas 3 articles
-
urbanoids 1 articles
-
video 47 articles
-
webdesign 7 articles
-
works 151 articles
Archives:
-
2007 22 articles
-
2008 32 articles
-
2009 66 articles
-
2010 74 articles
-
2011 74 articles
-
2012 47 articles
-
2013 31 articles
-
2014 38 articles
-
2015 28 articles
-
2016 36 articles
-
2017 41 articles
-
2018 46 articles
-
2019 59 articles
-
2020 18 articles
-
2021 20 articles
-
2022 7 articles
-
2023 25 articles
-
2024 14 articles
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.
#!/usr/bin/pythonimport sys,os,timer = os.system("xprintidle")if r != 0: print "Error: xprintidle was not found, and must be installed for this program to run" sys.exit()total_idle = 0def uptime(): "returns uptime in minutes" with open("/proc/uptime", "r") as f: uptime_seconds = float(f.readline().split()[0]) return int(uptime_seconds)/60 return 0def idletime(): "returns idle time in minutes" global total_idle r = os.popen("xprintidle") idle_minutes = int(r.read())/60000 if idle_minutes > 1: total_idle += 1 return total_idle def formattime(minutes): "formats atime in minutes to HH:MM" hours = minutes/60 restminutes = minutes%60 return str(hours).zfill(2)+":"+str(restminutes).zfill(2) def writetime(): "writes current activity time to a file" strtime = formattime(uptime() - idletime()) print ("active time: "+strtime) fil = open(os.path.expanduser("~") + os.sep + ".activitytime","wb") fil.write(str(strtime)) fil.close() def readtime(): "reads a temp file and adjusts elapsed idle" global total_idle fpath = os.path.expanduser("~") + os.sep + ".activitytime" if os.path.exists(fpath): fil = open(fpath,"r") r = fil.read() fil.close() t = r.split(":") minutes = int(t[0])*60 + int(t[1]) 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 writetime() else: # with an argument, for ex --append, restart from currently saved time readtime() while True: time.sleep(60) writetime()