From 75140c77b40b802c8b9c587785557123321707ea Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sun, 10 Sep 2017 18:37:11 +0200 Subject: [PATCH] [modules/currency] Make output format configurable Add two format strings: * sourceformat to specify the "base" format * destinationdelimiter to format how multiple rates are delimited --- bumblebee/modules/currency.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bumblebee/modules/currency.py b/bumblebee/modules/currency.py index 068a6f6..81d533e 100644 --- a/bumblebee/modules/currency.py +++ b/bumblebee/modules/currency.py @@ -10,6 +10,9 @@ Parameters: * currency.interval: Interval in minutes between updates, default is 1. * currency.source: Source currency (defaults to "GBP") * currency.destination: Comma-separated list of destination currencies (defaults to "USD,EUR") + * currency.sourceformat: String format for source formatting; Defaults to "{}: {}" and has two variables, + the base symbol and the rate list + * currency.destinationdelimiter: Delimiter used for separating individual rates (defaults to "|") Note: source and destination names right now must correspond to the names used by the API of http://fixer.io """ @@ -48,7 +51,10 @@ class Module(bumblebee.engine.Module): for sym in self._data["rates"]: rates.append(u"{}{}".format(self._data["rates"][sym], SYMBOL[sym] if sym in SYMBOL else sym)) - return u"{}: {}".format(SYMBOL[self._base] if self._base in SYMBOL else self._base, u"/".join(rates)) + basefmt = u"{}".format(self.parameter("sourceformat", "{}: {}")) + ratefmt = u"{}".format(self.parameter("destinationdelimiter", "|")) + + return basefmt.format(SYMBOL[self._base] if self._base in SYMBOL else self._base, ratefmt.join(rates)) def update(self, widgets): timestamp = int(time.time())