From 39607dff956fe91cc3197d1ca7b6fd26ebb717e6 Mon Sep 17 00:00:00 2001 From: neingeist Date: Sat, 27 Nov 2021 15:00:45 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=F0=9F=8F=BB=E2=80=8D=E2=99=80?= =?UTF-8?q?=EF=B8=8F=20delete=20old=20script=20and=20update=20readme=20+?= =?UTF-8?q?=20requirements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 11 ++------ requirements.txt | 1 + task-recurring-delete | 62 ------------------------------------------- 3 files changed, 3 insertions(+), 71 deletions(-) create mode 100644 requirements.txt delete mode 100755 task-recurring-delete diff --git a/README.md b/README.md index b461316..b6c00cd 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,7 @@ -task-recurring-delete ---------------------- -Delete all overdue, recurring and duplicate taskwarrior tasks and keep only the -first of a kind. - -task-recurring-postpone ------------------------ +# task-recurring-postpone Postpone recurring task dupes to tomorrow and keep only two per parent task.
-Need the taskw Python bindings to run. These are workarounds for this issue: -https://bug.tasktools.org/browse/TW-1314. +Needs the taskw Python bindings to run (`pip install -r requirements.txt`) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..55ddadf --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +taskw diff --git a/task-recurring-delete b/task-recurring-delete deleted file mode 100755 index 24a8538..0000000 --- a/task-recurring-delete +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env python3 -# Delete all overdue, recurring & duplicate taskwarrior tasks and keep only the -# first of a kind. -# -# Needs the taskw Python bindings to run. - -__requires__ = ["taskw >= 0.8.3"] -import pkg_resources - -from subprocess import Popen, PIPE, STDOUT -from uuid import UUID - -import collections -import datetime -import os -import pytz -import taskw - - -def task_delete(uuid): - """Delete the given task.""" - - assert isinstance(uuid, UUID) - - # This is somewhat a hack, but as TaskWwarrior 2.4.0 does NOT disable - # the 'Do you want to delete all pending recurrences ...' confirmation - # on rc.confirmation=off, so this is necessary. - DEVNULL = open(os.devnull, 'wb') - p = Popen(['task', 'rc.confirmation=off', str(uuid), 'delete'], - stdin=PIPE, stdout=DEVNULL, stderr=STDOUT) - p.communicate(input=bytes('no', 'UTF-8')) - - -w = taskw.TaskWarrior(marshal=True) -tasks = w.load_tasks() - - -# Only (over-)due and recurring tasks are considered for deletion: -due_before = datetime.datetime.utcnow() -due_before = due_before.replace(tzinfo=pytz.utc) -recurring_tasks_due = [task for task in tasks['pending'] - if 'recur' in task - and 'parent' in task - and 'due' in task and task['due'] < due_before] - -# Delete all but the first of all (over-)due and duplicate tasks: -parents = collections.Counter([task['parent'] - for task in recurring_tasks_due]) -for parent in parents: - count = parents[parent] - if count > 1: - dupe_tasks = [task for task in recurring_tasks_due - if task['parent'] == parent] - dupe_tasks = sorted(dupe_tasks, key=lambda t: t['due']) - - dupe_tasks_to_keep = dupe_tasks[0:1] - dupe_tasks_to_trash = dupe_tasks[1:] - - print('Deleting {} duplicate due tasks: "{}"'.format( - len(dupe_tasks_to_trash), dupe_tasks_to_trash[0]['description'])) - for task in dupe_tasks_to_trash: - task_delete(task['uuid'])