2021-08-17 12:12:01 -04:00
|
|
|
#!/usr/bin/env python
|
2021-08-20 08:49:14 -04:00
|
|
|
""" Get completed tasks from taskwarrior and output a simple report """
|
2021-08-17 12:12:01 -04:00
|
|
|
import subprocess
|
|
|
|
import json
|
2021-08-23 17:10:17 -04:00
|
|
|
import itertools
|
|
|
|
import operator
|
2021-08-17 12:12:01 -04:00
|
|
|
from datetime import date
|
|
|
|
from dateutil.relativedelta import relativedelta, MO
|
2021-08-18 10:30:26 -04:00
|
|
|
import click
|
2021-08-17 12:12:01 -04:00
|
|
|
|
2023-01-31 14:44:23 -05:00
|
|
|
__version__ = "0.3.1"
|
2021-08-17 12:12:01 -04:00
|
|
|
|
2023-01-31 11:47:17 -05:00
|
|
|
def validate_tasks(tasks):
|
|
|
|
""" Validate tasks have a proejct, inject "None" if they don't """
|
|
|
|
try:
|
|
|
|
for task in tasks:
|
|
|
|
test = task["project"]
|
|
|
|
except KeyError:
|
|
|
|
task["project"] = "None"
|
|
|
|
return tasks
|
2021-08-18 10:30:26 -04:00
|
|
|
|
|
|
|
@click.command()
|
|
|
|
@click.version_option(__version__, prog_name="task-status")
|
|
|
|
@click.option("--uuid", is_flag=True, help="Display the task UUID")
|
2021-08-19 15:20:21 -04:00
|
|
|
@click.option("--header", is_flag=True, help="Display date header")
|
2021-10-26 13:21:57 -04:00
|
|
|
@click.option("--bullet", default="*", help="Character to use for bullets in list")
|
2021-08-24 10:02:40 -04:00
|
|
|
@click.option(
|
|
|
|
"--sort", is_flag=True, default=True, help="Alphabetically sort by project"
|
|
|
|
)
|
2021-10-26 13:21:57 -04:00
|
|
|
def main(uuid, header, bullet, sort):
|
2021-08-20 08:49:14 -04:00
|
|
|
"""Main function that does all the work for task_status"""
|
2021-08-17 12:12:01 -04:00
|
|
|
today = date.today()
|
|
|
|
last_monday = today + relativedelta(weekday=MO(-2))
|
|
|
|
|
2021-08-20 09:24:54 -04:00
|
|
|
task_command = [
|
|
|
|
"task",
|
|
|
|
f"end.after:{last_monday}",
|
|
|
|
"status_report:display",
|
|
|
|
"-home",
|
2021-10-25 14:17:01 -04:00
|
|
|
"-DELETED",
|
2023-01-31 11:47:17 -05:00
|
|
|
"-delegated",
|
2021-10-18 12:18:38 -04:00
|
|
|
"export",
|
2021-08-20 09:24:54 -04:00
|
|
|
]
|
2021-08-17 12:12:01 -04:00
|
|
|
tasks = subprocess.run(
|
2021-08-20 09:24:54 -04:00
|
|
|
task_command,
|
2021-08-18 10:30:26 -04:00
|
|
|
capture_output=True,
|
2021-08-20 08:49:14 -04:00
|
|
|
check=True,
|
2021-08-17 12:12:01 -04:00
|
|
|
)
|
2023-01-31 11:47:17 -05:00
|
|
|
entries = validate_tasks(json.loads(tasks.stdout.decode()))
|
2021-08-23 16:46:43 -04:00
|
|
|
output_list = []
|
2021-08-23 17:10:17 -04:00
|
|
|
project_list = []
|
2021-08-19 15:20:21 -04:00
|
|
|
if header:
|
|
|
|
print(f"Reporting from: {last_monday}")
|
2021-08-23 17:10:17 -04:00
|
|
|
for status_projects, status_entries in itertools.groupby(
|
|
|
|
entries, key=operator.itemgetter("project")
|
|
|
|
):
|
2021-08-24 10:02:40 -04:00
|
|
|
if status_projects not in project_list:
|
|
|
|
project_list.append(status_projects)
|
2021-08-23 17:10:17 -04:00
|
|
|
output_list.append(list(status_entries))
|
2021-08-24 10:02:40 -04:00
|
|
|
|
|
|
|
if sort:
|
|
|
|
project_list.sort()
|
2021-08-23 17:10:17 -04:00
|
|
|
for project in project_list:
|
2021-10-26 13:21:57 -04:00
|
|
|
print(f"{bullet} {project}")
|
2021-08-23 17:10:17 -04:00
|
|
|
for entry in entries:
|
|
|
|
if entry["project"] == project and uuid:
|
2021-10-26 13:21:57 -04:00
|
|
|
print(f'\t{bullet} {entry["description"]} ({entry["uuid"]})')
|
2021-08-26 15:32:49 -04:00
|
|
|
elif entry["project"] == project:
|
2021-10-26 13:21:57 -04:00
|
|
|
print(f'\t{bullet} {entry["description"]}')
|
2021-08-17 12:12:01 -04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2021-08-28 16:57:33 -04:00
|
|
|
main() # pylint: disable=no-value-for-parameter # pragma: no cover
|