Skip to content

Instantly share code, notes, and snippets.

@svandragt

svandragt/worklog.py

Last active Aug 1, 2019
Embed
What would you like to do?
WorkLogPy: Keep track of what you are working on (Python 3). Writes a timestamped message to a CSV file.
#!/usr/bin/env python3
#v2.2
from random import choice
from datetime import datetime
def wlog(answer,now):
with open(f"worklog-{now:%Y%m%d}.csv", "a") as f:
f.write(f'"{now}","{answer.strip()}"\n')
def main():
wlog('--start session--', datetime.now() )
while True:
try:
answer = input("Working on: ")
if answer.strip() == '':
break
now = datetime.now()
wlog(answer, now )
print(f"[{now:%a %H:%M}] ✓")
except EOFError:
break
wlog('--stop session--', now )
if __name__== "__main__":
main()
@svandragt

This comment has been minimized.

Copy link
Owner Author

@svandragt svandragt commented Apr 28, 2016

v1.0.3: only keep the file open to write, so that changes are always saved. Previous versions would keep the log open when the script was running, preventing dropbox syncing.

@svandragt

This comment has been minimized.

Copy link
Owner Author

@svandragt svandragt commented Aug 1, 2019

v2.2: ctrl-d or enter to quit. works on python2 default systems. f-strings, code more elegant. day based csv files.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment