Do not format large numbers + default to "auto"
Now the currency is inferred automatically from local ip. Note that if you use a VPN, you will get the wrong currency!
This commit is contained in:
parent
ff74e8377d
commit
75d8503329
1 changed files with 11 additions and 5 deletions
|
@ -26,10 +26,10 @@ except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
SYMBOL = {
|
SYMBOL = {
|
||||||
"GBP": u"£", "EUR": u"€", "USD": u"$", "JPY": u"¥"
|
"GBP": u"£", "EUR": u"€", "USD": u"$", "JPY": u"¥", "KRW": u"₩"
|
||||||
}
|
}
|
||||||
DEFAULT_DEST = "USD,EUR,GBP"
|
DEFAULT_DEST = "USD,EUR,GBP"
|
||||||
DEFAULT_SRC = "GBP"
|
DEFAULT_SRC = "auto"
|
||||||
|
|
||||||
API_URL = "https://markets.ft.com/data/currencies/ajax/conversion?baseCurrency={}&comparison={}"
|
API_URL = "https://markets.ft.com/data/currencies/ajax/conversion?baseCurrency={}&comparison={}"
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ class Module(bumblebee.engine.Module):
|
||||||
self.interval(1)
|
self.interval(1)
|
||||||
self._nextcheck = 0
|
self._nextcheck = 0
|
||||||
|
|
||||||
src = self.parameter("source", "auto")
|
src = self.parameter("source", DEFAULT_SRC)
|
||||||
if src == "auto":
|
if src == "auto":
|
||||||
self._base = self.find_local_currency()
|
self._base = self.find_local_currency()
|
||||||
else:
|
else:
|
||||||
|
@ -60,8 +60,8 @@ class Module(bumblebee.engine.Module):
|
||||||
|
|
||||||
rates = []
|
rates = []
|
||||||
for sym, rate in self._data:
|
for sym, rate in self._data:
|
||||||
rate = float(rate)
|
rate = self.fmt_rate(rate)
|
||||||
rates.append(u"{:.3g}{}".format(rate, SYMBOL[sym] if sym in SYMBOL else sym))
|
rates.append(u"{}{}".format(rate, SYMBOL[sym] if sym in SYMBOL else sym))
|
||||||
|
|
||||||
basefmt = u"{}".format(self.parameter("sourceformat", "1{}={}"))
|
basefmt = u"{}".format(self.parameter("sourceformat", "1{}={}"))
|
||||||
ratefmt = u"{}".format(self.parameter("destinationdelimiter", "="))
|
ratefmt = u"{}".format(self.parameter("destinationdelimiter", "="))
|
||||||
|
@ -99,5 +99,11 @@ class Module(bumblebee.engine.Module):
|
||||||
except:
|
except:
|
||||||
return DEFAULT_SRC
|
return DEFAULT_SRC
|
||||||
|
|
||||||
|
def fmt_rate(self, rate):
|
||||||
|
float_rate = float(rate.replace(',', ''))
|
||||||
|
if not 0.01 < float_rate < 100:
|
||||||
|
return rate
|
||||||
|
else:
|
||||||
|
return "%.3g" % float_rate
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue