From 6b9847bf7f72eb9fa9da749f5043e8a91a1977ae Mon Sep 17 00:00:00 2001 From: neingeist Date: Wed, 27 Oct 2021 15:49:42 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20task-recurring-postpone:=20Postpone?= =?UTF-8?q?=20duplicate=20recurring=20tasks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 ++++++++++-- task-recurring-postpone | 27 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100755 task-recurring-postpone diff --git a/README.md b/README.md index f267bcb..b461316 100644 --- a/README.md +++ b/README.md @@ -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 + +
+ +Need the taskw Python bindings to run. These are workarounds for this issue: +https://bug.tasktools.org/browse/TW-1314. diff --git a/task-recurring-postpone b/task-recurring-postpone new file mode 100755 index 0000000..3b55a3b --- /dev/null +++ b/task-recurring-postpone @@ -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)