-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoverdue_bump.py
More file actions
79 lines (66 loc) · 2.26 KB
/
Copy pathoverdue_bump.py
File metadata and controls
79 lines (66 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
"""Bump priority of overdue tasks to a target priority level.
Finds tasks where due_date < today, status not in (done, archived, cancelled),
and current priority is lower than the target. Updates them to target priority.
"""
import argparse
import sys
from db_utils import (
DB_PATH,
TASK_PRIORITIES,
TaskDAO,
get_conn,
)
def run(db_path: str, target_priority: str, dry_run: bool) -> int:
if target_priority not in TASK_PRIORITIES:
print(
f"Error: invalid priority '{target_priority}'. "
f"Choose from: {', '.join(TASK_PRIORITIES)}",
file=sys.stderr,
)
return 1
if target_priority == TASK_PRIORITIES[0]:
print(f"No priorities lower than '{target_priority}' — nothing to bump.")
return 0
with get_conn(db_path) as conn:
candidates = TaskDAO.bump_overdue_priority(
conn,
target_priority,
dry_run=dry_run,
tool_name="overdue_bump.run",
)
if dry_run:
if not candidates:
print("Dry run: no overdue tasks would be bumped.")
else:
print(
f"Dry run: {len(candidates)} task(s) would be bumped to '{target_priority}':"
)
for row in candidates:
print(
f" [{row['id']}] {row['title']!r} "
f"priority={row['priority']} due={row['due_date']}"
)
else:
print(f"Bumped {len(candidates)} task(s) to '{target_priority}'.")
return 0
def main() -> None:
parser = argparse.ArgumentParser(
description="Bump priority of overdue tasks to a target priority level."
)
parser.add_argument("--db", default=DB_PATH, help="Path to the SQLite DB")
parser.add_argument(
"--target",
default="high",
choices=TASK_PRIORITIES,
help="Target priority to bump overdue tasks to (default: high)",
)
parser.add_argument(
"--dry-run",
action="store_true",
help="Show matching tasks without updating",
)
args = parser.parse_args()
sys.exit(run(args.db, args.target, args.dry_run))
if __name__ == "__main__":
main()