commit d2f71ccb5265f4a8aa444fe02ebcbad5ccba5416 Author: Stanislav N. aka pztrn Date: Wed Jul 27 17:31:36 2022 +0500 Initial commit with first hook which sets due date to the end of day. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d28bd7a --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +.vscode +*DS_Store* diff --git a/README.md b/README.md new file mode 100644 index 0000000..dc13808 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# TaskWarrior hooks + +This repository contains TaskWarrior hooks I'm using. + +## Hooks list + +| Hook name | Description | Dependencies | +| --------- | ----------- | ------------ | +| due-eod | Sets 'due' field to end of day, replacing default "00:00:00" with "23:59:59". | Python 3.7+ | + +## Installing + +Clone repository somewhere and create symlinks to hooks directory. Usually it is `${HOME}/.task/hooks`. Create this directory if not present. + +See hooks list above for dependencies needed. + +There are no makefile or other installation scripts intentionally, **you have to read [this document](https://taskwarrior.org/docs/hooks.html) and understand it!** + +## Reporting bugs + +Please go to [my gitea](https://code.pztrn.name/misc/taskwarrior_hooks) for bug reporting. All other places are mirrors. diff --git a/due-eod.py b/due-eod.py new file mode 100755 index 0000000..fd29399 --- /dev/null +++ b/due-eod.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 + +# TaskWarrior's hook that sets due date to the end of date. +# By default TaskWarrior sets it to 00:00:00. + +import datetime +import json +import sys + + +def get_task_data() -> str: + """ + Gets task data from stdin. + + It might be first line on task addition and second line on task modification. + + :return: str + """ + input_data = sys.stdin.readlines() + + with open("/Users/pztrn/TEMP/abracadabra", "w") as f: + f.write(input_data[-1]) + + return input_data[-1] + + +task_data_raw = get_task_data() + +task_data = json.loads(task_data_raw) + +if "due" in task_data: + new_due_ts = datetime.datetime.strptime(task_data["due"], "%Y%m%dT%H%M%S%z").astimezone() + if new_due_ts.hour != 23 and new_due_ts.minute != 59 and new_due_ts.second != 59: + new_due_ts = new_due_ts.replace(hour = 23, minute = 59, second = 59) + + task_data["due"] = new_due_ts.astimezone(tz = datetime.timezone.utc).strftime("%Y%m%dT%H%M%SZ") + +print(json.dumps(task_data, ensure_ascii = False)) +sys.exit(0)