-
-
Save wrgoldstein/99c54d358375099d8a962968403ef62e to your computer and use it in GitHub Desktop.
dead simple activity recorder.
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
#!/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:])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Save this file as
/usr/local/bin/i
, use on the command line likeand then view the result: