nxy/nxy/plugins/bitcoin.py
2017-05-29 18:44:26 +02:00

29 lines
848 B
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 Bitcoin(Plugin):
requires = ['irc3.plugins.command']
@command
def btc(self, mask: IrcString, channel: 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[BitStamp]\x0F ' \
'Current: \x02\x037${last:,.2f}\x0F - ' \
'High: \x02\x033${high:,.2f}\x0F - ' \
'Low: \x02\x035${low:,.2f}\x0F - ' \
'Volume: \x02฿{volume:,.2f}'.format(**values)