From 925ed42b864a88d11f349cc430bfb07e41008cc2 Mon Sep 17 00:00:00 2001 From: Chris Berkhout Date: Mon, 31 May 2021 18:59:38 +0200 Subject: [PATCH] Don't print a blank line for ledger or beancount when there are no prices. --- src/pricehist/outputs/beancount.py | 6 +++--- src/pricehist/outputs/ledger.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pricehist/outputs/beancount.py b/src/pricehist/outputs/beancount.py index 9f2b2b1..5be3711 100644 --- a/src/pricehist/outputs/beancount.py +++ b/src/pricehist/outputs/beancount.py @@ -5,7 +5,7 @@ from .baseoutput import BaseOutput class Beancount(BaseOutput): def format(self, series, source=None, fmt=Format()): - lines = [] + output = "" for price in series.prices: # TODO warn if fmt settings make an invalid number (not . for decimal) # TODO warn if fmt settings make an invalid quote (not right/rightspace) @@ -13,8 +13,8 @@ class Beancount(BaseOutput): base = fmt.base or series.base quote = fmt.quote or series.quote quote_amount = fmt.format_quote_amount(quote, price.amount) - lines.append(f"{date} price {base} {quote_amount}") - return "\n".join(lines) + "\n" + output += f"{date} price {base} {quote_amount}\n" + return output # NOTE: Beancount always has commodity to the right. It seems to be possible to diff --git a/src/pricehist/outputs/ledger.py b/src/pricehist/outputs/ledger.py index 474d2ee..054c998 100644 --- a/src/pricehist/outputs/ledger.py +++ b/src/pricehist/outputs/ledger.py @@ -5,14 +5,14 @@ from .baseoutput import BaseOutput class Ledger(BaseOutput): def format(self, series, source=None, fmt=Format()): - lines = [] + output = "" for price in series.prices: date = fmt.format_date(price.date) base = fmt.base or series.base quote = fmt.quote or series.quote quote_amount = fmt.format_quote_amount(quote, price.amount) - lines.append(f"P {date} {fmt.time} {base} {quote_amount}") - return "\n".join(lines) + "\n" + output += f"P {date} {fmt.time} {base} {quote_amount}\n" + return output # https://www.ledger-cli.org/3.0/doc/ledger3.html#Commodities-and-Currencies # > The commodity may be any non-numeric string that does not contain a