From 45e8222d2f657fb4ea1a7208e3145f3815a44763 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Mon, 25 Jan 2021 15:48:41 +0100 Subject: Don't crash when no records are found --- fracture/__main__.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'fracture') diff --git a/fracture/__main__.py b/fracture/__main__.py index 90f2dd3..a4be0b9 100644 --- a/fracture/__main__.py +++ b/fracture/__main__.py @@ -125,17 +125,20 @@ def summarize(xlsx=False, year=None, quarter=None): rows = sorted((map(lambda x: x.to_row(), invoices)), key=lambda x: x["type"]) - keys = list(rows[0].keys()) - # FIXME all rows don't match and I'm putting them together in weird orders - for r in rows: - for k in r.keys(): - if k not in keys: - keys.append(k) - import sys - wrtr = DictWriter(sys.stdout, keys) - wrtr.writeheader() - for r in rows: - wrtr.writerow(r) + if len(rows) > 0: + keys = list(rows[0].keys()) + # FIXME all rows don't match and I'm putting them together in weird orders + for r in rows: + for k in r.keys(): + if k not in keys: + keys.append(k) + import sys + wrtr = DictWriter(sys.stdout, keys) + wrtr.writeheader() + for r in rows: + wrtr.writerow(r) + else: + print("No data available for this period") @command def render(id, template=None, type=None, list_templates=None): -- cgit v1.2.3