From 1c50050a054863339eab84c7d992b69ee86b3347 Mon Sep 17 00:00:00 2001 From: Alex Kelly Date: Mon, 23 Aug 2021 16:46:43 -0400 Subject: [PATCH] chore: attempt to fix #1, but instead made it fail the same way with completely different logic --- task_status/task_status.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/task_status/task_status.py b/task_status/task_status.py index 92e85ea..ef30925 100755 --- a/task_status/task_status.py +++ b/task_status/task_status.py @@ -5,6 +5,8 @@ import json from datetime import date from dateutil.relativedelta import relativedelta, MO import click +import itertools +import operator __version__ = "0.2.0" @@ -32,20 +34,18 @@ def main(uuid, header): ) entries = json.loads(tasks.stdout.decode()) - last_project = "" + output_list = [] if header: print(f"Reporting from: {last_monday}") - for entry in entries: - try: - if entry["project"] != last_project: - last_project = entry["project"] - except KeyError: - entry["project"] = "" - print(f"* {entry['project']}") - if uuid: - print(f"\t* {entry['description']} ({entry['uuid']})") - else: - print(f"\t* {entry['description']}") + for i, g in itertools.groupby(entries, key=operator.itemgetter("project")): + output_list.append(list(g)) + for project in output_list: + print(f'* {project[0]["project"]}') + for entry in project: + if uuid: + print(f'\t* {entry["description"]} ({entry["uuid"]})') + else: + print(f'\t* {entry["description"]}') if __name__ == "__main__":