Skip to content

Instantly share code, notes, and snippets.

@wrgoldstein
Last active December 20, 2023 17:29
Show Gist options
  • Save wrgoldstein/99c54d358375099d8a962968403ef62e to your computer and use it in GitHub Desktop.
Save wrgoldstein/99c54d358375099d8a962968403ef62e to your computer and use it in GitHub Desktop.
dead simple activity recorder.
#!/opt/homebrew/bin/python3
import datetime
import sys
import os
from pathlib import Path
home = os.path.expanduser('~')
fname = f"{home}/whatidid"
if not os.path.isfile(fname):
Path(fname).touch()
def record(msg):
with open(fname, "r+") as f:
for line in reversed(f.readlines()):
if line.startswith("=="):
date = line.split("==")[1]
if str(datetime.date.today()) == date:
break
else:
f.write(f"\n=={datetime.date.today()}==\n")
t1 = ":".join(str(datetime.datetime.now().time()).split(".")[0].split(":")[:2])
last = list(filter(lambda x: not x.startswith("=="), open(fname).readlines()))[-1]
with open(fname, "a") as f:
f.write(f"{t1} {msg}\n")
if __name__ == "__main__":
if len(sys.argv) == 1:
print(open(fname).read())
elif len(sys.argv) == 2:
record(sys.argv[1])
else:
record(" ".join(sys.argv[1:]))
@wrgoldstein
Copy link
Author

Save this file as /usr/local/bin/i, use on the command line like

$ i had coffee

and then view the result:

$ i
==2023-12-20==
12:28 had coffee

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