49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
import irc3
|
|
import requests
|
|
|
|
from docopt import Dict as DocOptDict
|
|
from irc3.plugins.command import command
|
|
from irc3.utils import IrcString
|
|
|
|
from . import Plugin
|
|
|
|
|
|
@irc3.plugin
|
|
class Coins(Plugin):
|
|
requires = ['irc3.plugins.command']
|
|
|
|
@command
|
|
def btc(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
|
"""Gets the Bitcoin values from BitStamp.
|
|
|
|
%%btc
|
|
"""
|
|
data = requests.get('https://www.bitstamp.net/api/ticker').json()
|
|
values = {k: float(data[k]) for k in ['last', 'high', 'low', 'volume']}
|
|
return '\x02[Bitcoin]\x02 ' \
|
|
'Current: \x02\x037${last:,.2f}\x0F - ' \
|
|
'High: \x02\x033${high:,.2f}\x0F - ' \
|
|
'Low: \x02\x034${low:,.2f}\x0F - ' \
|
|
'Volume: \x02฿{volume:,.2f}\x02'.format(**values)
|
|
|
|
@command
|
|
def eth(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
|
"""Gets the Ethereum values from etherscan.io.
|
|
|
|
%%eth
|
|
"""
|
|
volume = self._etherscan('ethsupply')
|
|
data = self._etherscan('ethprice')
|
|
return '\x02[EtherScan]\x02' \
|
|
'\x02\x0307 ${usd:,.2f}\x0F |\x02\x0307 {btc:,.5f} BTC\x0F ' \
|
|
'- Volume: \x02{volume:,.2f}\x02' \
|
|
.format(usd=float(data['ethusd']),
|
|
btc=float(data['ethbtc']),
|
|
volume=float(int(volume) / 1000000000000000000))
|
|
|
|
@staticmethod
|
|
def _etherscan(action: str):
|
|
return requests.get('https://api.etherscan.io/api?module=stats&action='
|
|
'{action}'.format(action=action)).json()['result']
|