From 0c7697e33ba07a0631261b12b7dcc1dd976680ef Mon Sep 17 00:00:00 2001 From: Nils Schweinsberg Date: Sun, 15 Oct 2017 03:49:08 +0200 Subject: [PATCH] Move __currency out of Coins class --- bot/coins.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/bot/coins.py b/bot/coins.py index ac3057a..749d529 100644 --- a/bot/coins.py +++ b/bot/coins.py @@ -6,26 +6,23 @@ from irc3.utils import IrcString 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): 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 = { - 'usd': Coins.__currency('usd', prefix='$'), - 'eur': Coins.__currency('eur', suffix='€'), - 'eth': Coins.__currency('eth', suffix='Ξ'), - 'btc': Coins.__currency('btc', suffix='฿'), - 'xmr': Coins.__currency('xmr'), + 'usd': _currency('usd', prefix='$'), + 'eur': _currency('eur', suffix='€'), + 'eth': _currency('eth', suffix='Ξ'), + 'btc': _currency('btc', suffix='฿'), + 'xmr': _currency('xmr'), } @command