53 lines
1.5 KiB
Python
Executable file
53 lines
1.5 KiB
Python
Executable file
#!/usr/bin/env python
|
|
|
|
"""Manage Taskwarrior notes"""
|
|
|
|
import argparse
|
|
import logging
|
|
import os
|
|
import sys
|
|
import datetime
|
|
|
|
NOTES_DIR = "~/kitaab/vimwiki/task-notes"
|
|
EDITOR = os.environ["EDITOR"]
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
|
|
def write_note(task_id: int):
|
|
"""Open `$EDITOR` to take notes about task with ID `task_id`."""
|
|
task_uuid = os.popen(f"task _get {task_id}.uuid").read().rstrip()
|
|
|
|
if not task_uuid:
|
|
logging.error(f"{task_id} has no UUID!")
|
|
sys.exit(1)
|
|
|
|
logging.debug(f"Task {task_id} has UUID {task_uuid}")
|
|
|
|
notes_dir = os.path.expanduser(NOTES_DIR)
|
|
os.makedirs(notes_dir, exist_ok=True)
|
|
notes_basename = f"{task_uuid}.md"
|
|
notes_file = os.path.join(notes_dir, notes_basename)
|
|
logging.debug(f"Notes file is {notes_file}")
|
|
|
|
if not os.path.exists(notes_file):
|
|
logging.info("Adding description to empty notes file")
|
|
task_description = os.popen(f"task _get {task_id}.description").read()
|
|
time = datetime.datetime.now().strftime("%y-%m-%d %H:%M")
|
|
|
|
with open(notes_file, "w") as f:
|
|
f.write(f"%title: {task_description}\n")
|
|
f.write(":task:\n")
|
|
f.write(f"%date: {time}\n\n")
|
|
f.flush()
|
|
|
|
os.execlp(EDITOR, EDITOR, notes_file)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description="Write Taskwarrior notes")
|
|
parser.add_argument('task_id', metavar='ID', type=int, help="ID of the task to note")
|
|
args = parser.parse_args()
|
|
|
|
write_note(args.task_id)
|