[modules/currency] quotes
This commit is contained in:
parent
92d30efec7
commit
3a0b4c8b38
1 changed files with 18 additions and 18 deletions
|
@ -8,11 +8,11 @@ Requires the following python packages:
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
* currency.interval: Interval in minutes between updates, default is 1.
|
* currency.interval: Interval in minutes between updates, default is 1.
|
||||||
* currency.source: Source currency (ex. "GBP", "EUR"). Defaults to "auto", which infers the local one from IP address.
|
* currency.source: Source currency (ex. 'GBP', 'EUR'). Defaults to 'auto', which infers the local one from IP address.
|
||||||
* currency.destination: Comma-separated list of destination currencies (defaults to "USD,EUR")
|
* 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,
|
* currency.sourceformat: String format for source formatting; Defaults to '{}: {}' and has two variables,
|
||||||
the base symbol and the rate list
|
the base symbol and the rate list
|
||||||
* currency.destinationdelimiter: Delimiter used for separating individual rates (defaults to "|")
|
* 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 https://markets.ft.com
|
Note: source and destination names right now must correspond to the names used by the API of https://markets.ft.com
|
||||||
"""
|
"""
|
||||||
|
@ -32,13 +32,13 @@ import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
SYMBOL = {
|
SYMBOL = {
|
||||||
"GBP": u"£", "EUR": u"€", "USD": u"$", "JPY": u"¥", "KRW": u"₩"
|
'GBP': u'£', 'EUR': u'€', 'USD': u'$', 'JPY': u'¥', 'KRW': u'₩'
|
||||||
}
|
}
|
||||||
DEFAULT_DEST = "USD,EUR,auto"
|
DEFAULT_DEST = 'USD,EUR,auto'
|
||||||
DEFAULT_SRC = "GBP"
|
DEFAULT_SRC = 'GBP'
|
||||||
|
|
||||||
API_URL = "https://markets.ft.com/data/currencies/ajax/conversion?baseCurrency={}&comparison={}"
|
API_URL = 'https://markets.ft.com/data/currencies/ajax/conversion?baseCurrency={}&comparison={}'
|
||||||
LOCATION_URL = "https://ipvigilante.com/"
|
LOCATION_URL = 'https://ipvigilante.com/'
|
||||||
|
|
||||||
|
|
||||||
def get_local_country():
|
def get_local_country():
|
||||||
|
@ -70,14 +70,14 @@ class Module(bumblebee.engine.Module):
|
||||||
self.interval(1)
|
self.interval(1)
|
||||||
self._nextcheck = 0
|
self._nextcheck = 0
|
||||||
|
|
||||||
src = self.parameter("source", DEFAULT_SRC)
|
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:
|
||||||
self._base = src
|
self._base = src
|
||||||
|
|
||||||
self._symbols = []
|
self._symbols = []
|
||||||
for d in self.parameter("destination", DEFAULT_DEST).split(","):
|
for d in self.parameter('destination', DEFAULT_DEST).split(','):
|
||||||
if d == 'auto':
|
if d == 'auto':
|
||||||
new = self.find_local_currency()
|
new = self.find_local_currency()
|
||||||
else:
|
else:
|
||||||
|
@ -87,7 +87,7 @@ class Module(bumblebee.engine.Module):
|
||||||
|
|
||||||
def price(self, widget):
|
def price(self, widget):
|
||||||
if len(self._data) == 0:
|
if len(self._data) == 0:
|
||||||
return "?"
|
return '?'
|
||||||
|
|
||||||
rates = []
|
rates = []
|
||||||
for sym, rate in self._data:
|
for sym, rate in self._data:
|
||||||
|
@ -96,10 +96,10 @@ class Module(bumblebee.engine.Module):
|
||||||
rates.append(format_currency(rate_float, sym))
|
rates.append(format_currency(rate_float, sym))
|
||||||
else:
|
else:
|
||||||
rate = self.fmt_rate(rate)
|
rate = self.fmt_rate(rate)
|
||||||
rates.append(u"{}{}".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", "{}={}"))
|
basefmt = u'{}'.format(self.parameter('sourceformat', '{}={}'))
|
||||||
ratefmt = u"{}".format(self.parameter("destinationdelimiter", "="))
|
ratefmt = u'{}'.format(self.parameter('destinationdelimiter', '='))
|
||||||
|
|
||||||
if format_currency:
|
if format_currency:
|
||||||
base_val = format_currency(1, self._base)
|
base_val = format_currency(1, self._base)
|
||||||
|
@ -119,7 +119,7 @@ class Module(bumblebee.engine.Module):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def find_local_currency(self):
|
def find_local_currency(self):
|
||||||
'''Use geolocation lookup to find local currency'''
|
"""Use geolocation lookup to find local currency"""
|
||||||
try:
|
try:
|
||||||
country = get_local_country()
|
country = get_local_country()
|
||||||
currency_map = load_country_to_currency()
|
currency_map = load_country_to_currency()
|
||||||
|
@ -132,7 +132,7 @@ class Module(bumblebee.engine.Module):
|
||||||
if not 0.01 < float_rate < 100:
|
if not 0.01 < float_rate < 100:
|
||||||
ret = rate
|
ret = rate
|
||||||
else:
|
else:
|
||||||
ret = "%.3g" % float_rate
|
ret = '%.3g' % float_rate
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue