From ba38a9d4a0144b49ba3e1f0e31f1a91e91f5ceff Mon Sep 17 00:00:00 2001 From: "Michael P. Soulier" Date: Wed, 10 May 2017 15:38:44 -0400 Subject: [PATCH] Added a currencies parameter to the stock ticker. --- bumblebee/modules/stock.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/bumblebee/modules/stock.py b/bumblebee/modules/stock.py index 1a23435..0e8b48a 100644 --- a/bumblebee/modules/stock.py +++ b/bumblebee/modules/stock.py @@ -9,6 +9,7 @@ Requires the following python packages: Parameters: * stock.symbols : Comma-separated list of symbols to fetch * stock.change : Should we fetch change in stock value (defaults to True) + * stock.currencies : List of symbols to go with the values (default $) """ import bumblebee.input @@ -24,12 +25,25 @@ class Module(bumblebee.engine.Module): ) self._symbols = self.parameter("symbols", "") self._change = self.parameter("change", True) + self._currencies = self.parameter('currencies', None) self._baseurl = 'http://download.finance.yahoo.com/d/quotes.csv' self._value = self.fetch() + if not self._currencies: + self._currencies = '$' * len(self._symbols) + + # The currencies could be unicode, like the € symbol. Convert to a unicode object. + self._currencies = self._currencies.decode('utf-8', 'ignore') + def value(self, widget): - results = ["$%s" % val for val in self._value.split('\n')] - return ' '.join(results) + results = [] + for i, val in enumerate(self._value.split('\n')): + try: + currency_symbol = self._currencies[i] + except: + currency_symbol = '$' + results.append('%s%s' % (currency_symbol, val)) + return u' '.join(results) def fetch(self): if self._symbols: