Initial commit with first hook which sets due date to the end of day.
This commit is contained in:
commit
d2f71ccb52
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
.idea
|
||||
.vscode
|
||||
*DS_Store*
|
21
README.md
Normal file
21
README.md
Normal file
@ -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.
|
39
due-eod.py
Executable file
39
due-eod.py
Executable file
@ -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)
|
Loading…
Reference in New Issue
Block a user