Last active
February 1, 2023 19:53
-
-
Save ssj71/8b8fa9c93160cb15a7ed7de3c8f435aa to your computer and use it in GitHub Desktop.
Time Logging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#spencer | |
# just run this when i3lock starts | |
d=$(date) | |
sleep 30 | |
if killall -0 i3lock; | |
then | |
echo $d screen locked >> ~/timecard | |
else | |
#it didn't stay locked long enough, don't count it | |
exit | |
fi | |
while : | |
do | |
sleep 30 | |
if ! killall -0 i3lock; | |
then | |
echo $(date) screen unlocked >> ~/timecard | |
exit | |
fi | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import dateutil.parser as dparse | |
import dateutil.relativedelta as ddelta | |
import os | |
card = open(os.path.expanduser("~/timecard"),'r') | |
day = None | |
pt = None | |
times = [] | |
for l in card: | |
d = dparse.parse(l,fuzzy_with_tokens=True) | |
if "screen locked" in d[1][-1]: | |
if pt: | |
#end of the session | |
dlt = ddelta.relativedelta(d[0],pt) | |
times.append(dlt.hours*60 + dlt.minutes + dlt.seconds/60.0) | |
pt = None | |
else: | |
#mismatch. ignore | |
pass | |
elif "screen unlocked" in d[1][-1]: | |
if not pt: | |
#start of a new session | |
pt = d[0] | |
if d[0].day == day: | |
#same day | |
pass | |
else: | |
#new day | |
#print summary | |
if day: | |
print(day,":",round(sum(times)/60.0,3),"hours,",len(times),"sessions",[round(f,2) for f in times]) | |
#setup next day | |
times = [] | |
day = pt.day | |
else: | |
#mismatch. ignore | |
pass | |
else: | |
#something else | |
pass | |
print(day,":",round(sum(times)/60.0,3),"hours",len(times),"sessions",[round(f,2) for f in times]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment