Merge branch 'msoulier-master'
This commit is contained in:
commit
fe91d5bc78
1 changed files with 17 additions and 2 deletions
|
@ -9,6 +9,7 @@ Requires the following python packages:
|
||||||
Parameters:
|
Parameters:
|
||||||
* stock.symbols : Comma-separated list of symbols to fetch
|
* stock.symbols : Comma-separated list of symbols to fetch
|
||||||
* stock.change : Should we fetch change in stock value (defaults to True)
|
* 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
|
import bumblebee.input
|
||||||
|
@ -24,12 +25,26 @@ class Module(bumblebee.engine.Module):
|
||||||
)
|
)
|
||||||
self._symbols = self.parameter("symbols", "")
|
self._symbols = self.parameter("symbols", "")
|
||||||
self._change = self.parameter("change", True)
|
self._change = self.parameter("change", True)
|
||||||
|
self._currencies = self.parameter('currencies', None)
|
||||||
self._baseurl = 'http://download.finance.yahoo.com/d/quotes.csv'
|
self._baseurl = 'http://download.finance.yahoo.com/d/quotes.csv'
|
||||||
self._value = self.fetch()
|
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.
|
||||||
|
if hasattr(self._currencies, "decode"):
|
||||||
|
self._currencies = self._currencies.decode("utf-8", "ignore")
|
||||||
|
|
||||||
def value(self, widget):
|
def value(self, widget):
|
||||||
results = ["$%s" % val for val in self._value.split('\n')]
|
results = []
|
||||||
return ' '.join(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):
|
def fetch(self):
|
||||||
if self._symbols:
|
if self._symbols:
|
||||||
|
|
Loading…
Reference in a new issue