Skip to content

Instantly share code, notes, and snippets.

@alt-romes
Last active March 8, 2021 10:52
Show Gist options
  • Save alt-romes/27eaf688259e7116841e92451a5988bb to your computer and use it in GitHub Desktop.
Save alt-romes/27eaf688259e7116841e92451a5988bb to your computer and use it in GitHub Desktop.
Simple program to count and log work time to a time log
#!/usr/bin/env python3
# Log Time:
# logtime.sh work 1h30m
# This will add an entry to the file in $logfilename of type "work: 1h30m" under the header for the day
#
# Usage suggestion:
# Dependencies: termdown @ https://github.com/trehn/termdown
# Bash Function:
# tasktimer(){
# if [ "$1" == "" ] || [ "$2" == "" ]; then
# echo "Usage: tasktimer task time"
# return
# fi
# termdown -s -f tinker-toy -T $1 $2 && logtime.sh $1 $2
# }
#
# Calling `tasktimer Work 1h30m` will display a terminal countdown for 1h30m and when done will add a work entry to the logfile
import sys
if len(sys.argv) < 3:
print("Usage:\n\tlogtime.sh \"log prefix\" \"time elapsed\"")
exit()
from datetime import datetime
# Change log file here
logfilename = "docs/time.log"
today = datetime.today().strftime("%B %d, %Y")
logHasToday = False
with open(logfilename, "r") as f:
for line in f.readlines():
if line.startswith("---") and line.find(today) > 0:
logHasToday = True
break
with open(logfilename, "a") as f:
if not logHasToday:
f.write("--- " + today + " ---\n")
f.write(sys.argv[1] + ": " + sys.argv[2] + "\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment