0
0
Fork 0

task-recurring-postpone: Postpone duplicate recurring tasks

master
neingeist 3 years ago committed by Gerber, Mike
parent ed49315091
commit 6b9847bf7f

@ -1,6 +1,14 @@
task-recurring-delete
---------------------
Delete all overdue, recurring and duplicate taskwarrior tasks and keep only the
first of a kind.
Needs the taskw Python bindings to run.
task-recurring-postpone
-----------------------
Postpone recurring task dupes to tomorrow and keep only two per parent task.
This is a workaround for this issue: https://bug.tasktools.org/browse/TW-1314
<hr/>
Need the taskw Python bindings to run. These are workarounds for this issue:
https://bug.tasktools.org/browse/TW-1314.

@ -0,0 +1,27 @@
#!/usr/bin/python3
import datetime
from taskw import TaskWarrior
from pprint import pprint
from operator import itemgetter
from itertools import groupby
w = TaskWarrior(marshal=True)
tasks = w.load_tasks()["pending"]
tasks = list(filter(lambda t: t.get("status") == "pending", tasks))
# Recurring tasks have a "parent"
tasks = list(filter(lambda t: t.get("parent") is not None, tasks))
for k, g in groupby(sorted(tasks, key=itemgetter("parent")), key=itemgetter("parent")):
# Postpone all but the two most urgent tasks
to_postpone = sorted(g, key=itemgetter("urgency"))[:-2]
if not to_postpone:
continue
print(f"Postponing {len(to_postpone)}x {to_postpone[0]['description']}")
for t in to_postpone:
t["status"] = "waiting"
t["wait"] = datetime.datetime.combine(datetime.date.today(), datetime.datetime.min.time()) \
+ datetime.timedelta(days=1)
w.task_update(t)