diff options
author | Ekaitz Zarraga <ekaitz@elenq.tech> | 2021-01-25 15:48:41 +0100 |
---|---|---|
committer | Ekaitz Zarraga <ekaitz@elenq.tech> | 2021-01-25 15:48:41 +0100 |
commit | 45e8222d2f657fb4ea1a7208e3145f3815a44763 (patch) | |
tree | 12d4a3f025287caba8ab3815e3c4483543301f63 /fracture | |
parent | 7011ba2cc411164e25d0019ba875069096ffb4f6 (diff) |
Don't crash when no records are found
Diffstat (limited to 'fracture')
-rw-r--r-- | fracture/__main__.py | 25 |
1 files changed, 14 insertions, 11 deletions
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): |