Fix data request for coins

This commit is contained in:
Nils Schweinsberg 2017-10-15 03:51:12 +02:00
parent 0c7697e33b
commit f02e90ecd8

View File

@ -55,12 +55,12 @@ class Coins(Plugin):
if currency not in self.CURRENCIES or crypto == currency: if currency not in self.CURRENCIES or crypto == currency:
return '\x02[{}]\x02 Can\'t convert or invalid currency: {}'.format(crypto.upper(), currency) return '\x02[{}]\x02 Can\'t convert or invalid currency: {}'.format(crypto.upper(), currency)
currency = self.CURRENCIES[currency]
data = requests.get(self.API_URL.format(crypto=crypto, market=market, currency=currency)) data = requests.get(self.API_URL.format(crypto=crypto, market=market, currency=currency))
if not data: if not data:
return '\x02[{}]\x02 No data received'.format(crypto) return '\x02[{}]\x02 No data received'.format(crypto)
to_currency = self.CURRENCIES[currency]
result = data.json()['result'] result = data.json()['result']
return '\x02[{crypto}]\x02 ' \ return '\x02[{crypto}]\x02 ' \
'Current: \x02\x0307{last}\x0F - ' \ 'Current: \x02\x0307{last}\x0F - ' \
@ -69,8 +69,8 @@ class Coins(Plugin):
'Change: \x02\x0307{change:,.2f}%\x0F - ' \ 'Change: \x02\x0307{change:,.2f}%\x0F - ' \
'Volume: \x02\x0307{volume}\x0F' \ 'Volume: \x02\x0307{volume}\x0F' \
.format(crypto=crypto.upper(), .format(crypto=crypto.upper(),
last=currency(result['price']['last']), last=to_currency(result['price']['last']),
high=currency(result['price']['high']), high=to_currency(result['price']['high']),
low=currency(result['price']['low']), low=to_currency(result['price']['low']),
change=result['price']['change']['percentage'] * 100, change=result['price']['change']['percentage'] * 100,
volume=result['volume']) volume=result['volume'])