Move __currency out of Coins class

This commit is contained in:
Nils Schweinsberg 2017-10-15 03:49:08 +02:00
parent 3f6c840d86
commit 0c7697e33b

View File

@ -6,26 +6,23 @@ from irc3.utils import IrcString
from . import Plugin from . import Plugin
def _currency(name, prefix=None, suffix=None):
def tostr(value):
return '{prefix}{value:,.2f}{suffix}'.format(
prefix=prefix or '',
suffix=suffix or ('' if (prefix or suffix) else (' ' + name)),
value=value)
return tostr
class Coins(Plugin): class Coins(Plugin):
API_URL = 'https://api.cryptowat.ch/markets/{market}/{crypto}{currency}/summary' API_URL = 'https://api.cryptowat.ch/markets/{market}/{crypto}{currency}/summary'
@staticmethod
def __currency(name, prefix=None, suffix=None):
def tostr(value):
return '{prefix}{value:,.2f}{suffix}'.format(
prefix=prefix or '',
suffix=suffix or ('' if (prefix or suffix) else (' ' + name)),
value=value)
return tostr
CURRENCIES = { CURRENCIES = {
'usd': Coins.__currency('usd', prefix='$'), 'usd': _currency('usd', prefix='$'),
'eur': Coins.__currency('eur', suffix=''), 'eur': _currency('eur', suffix=''),
'eth': Coins.__currency('eth', suffix='Ξ'), 'eth': _currency('eth', suffix='Ξ'),
'btc': Coins.__currency('btc', suffix='฿'), 'btc': _currency('btc', suffix='฿'),
'xmr': Coins.__currency('xmr'), 'xmr': _currency('xmr'),
} }
@command @command