Added error messages to coins plugin
This commit is contained in:
parent
87a0111e74
commit
b970f38344
|
@ -26,7 +26,7 @@ class Coins(Plugin):
|
||||||
|
|
||||||
%%btc [<currency>]
|
%%btc [<currency>]
|
||||||
"""
|
"""
|
||||||
return self.cryptowat_summary('btc', args.get('<currency>', 'usd'))
|
return self.cryptowat_summary('btc', args)
|
||||||
|
|
||||||
@command
|
@command
|
||||||
def eth(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
def eth(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||||
|
@ -34,27 +34,29 @@ class Coins(Plugin):
|
||||||
|
|
||||||
%%eth [<currency>]
|
%%eth [<currency>]
|
||||||
"""
|
"""
|
||||||
return self.cryptowat_summary('eth', args.get('<currency>', 'usd'))
|
return self.cryptowat_summary('eth', args)
|
||||||
|
|
||||||
|
def cryptowat_summary(self, crypto: str, args: DocOptDict):
|
||||||
|
currency = args.get('<currency>', 'usd')
|
||||||
|
|
||||||
def cryptowat_summary(self, crypto: str, currency: str = 'usd'):
|
|
||||||
# Check if valid currency + crypto2currency
|
|
||||||
if currency not in self.CURRENCIES or crypto == currency:
|
if currency not in self.CURRENCIES or crypto == currency:
|
||||||
return
|
return '\x02[{}]\x02 Can\'t convert or invalid currency: {}'.format(crypto.upper(), currency)
|
||||||
|
|
||||||
# Send request to api
|
|
||||||
data = requests.get(self.API_URL.format(crypto=crypto, currency=currency))
|
data = requests.get(self.API_URL.format(crypto=crypto, currency=currency))
|
||||||
if data:
|
if not data:
|
||||||
result = data.json()['result']
|
return '\x02[{}]\x02 No data received'.format(crypto)
|
||||||
return '\x02[{crypto}]\x02 ' \
|
|
||||||
'Current: \x02\x0307{currency}{last:,.2f}\x0F - ' \
|
result = data.json()['result']
|
||||||
'High: \x02\x0303{currency}{high:,.2f}\x0F - ' \
|
return '\x02[{crypto}]\x02 ' \
|
||||||
'Low: \x02\x0304{currency}{low:,.2f}\x0F - ' \
|
'Current: \x02\x0307{currency}{last:,.2f}\x0F - ' \
|
||||||
'Change: \x02\x0307{change:,.2f}%\x0F - ' \
|
'High: \x02\x0303{currency}{high:,.2f}\x0F - ' \
|
||||||
'Volume: \x02\x0307{volume}\x0F' \
|
'Low: \x02\x0304{currency}{low:,.2f}\x0F - ' \
|
||||||
.format(crypto=crypto.upper(),
|
'Change: \x02\x0307{change:,.2f}%\x0F - ' \
|
||||||
currency=self.CURRENCIES[currency],
|
'Volume: \x02\x0307{volume}\x0F' \
|
||||||
last=result['price']['last'],
|
.format(crypto=crypto.upper(),
|
||||||
high=result['price']['high'],
|
currency=self.CURRENCIES[currency],
|
||||||
low=result['price']['low'],
|
last=result['price']['last'],
|
||||||
change=result['price']['change']['percentage'] * 100,
|
high=result['price']['high'],
|
||||||
volume=result['volume'])
|
low=result['price']['low'],
|
||||||
|
change=result['price']['change']['percentage'] * 100,
|
||||||
|
volume=result['volume'])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user