nxy/nxy/plugins/coins.py
2017-05-16 13:44:39 +02:00

33 lines
1008 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
from ..utils import fmt
# noinspection PyUnusedLocal
@irc3.plugin
class Coins(Plugin):
requires = [
'irc3.plugins.command',
]
@command
def btc(self, mask: IrcString, channel: IrcString, args: DocOptDict):
"""Bitcoin command.
%%btc
"""
data = requests.get('https://www.bitstamp.net/api/ticker').json()
return fmt('{bold}[BitStamp, 24h]{reset} '
'Current: {bold}{color}{orange}${last:,.2f}{reset} - '
'High: {bold}{color}{green}${high:,.2f}{reset} - '
'Low: {bold}{color}{maroon}${low:,.2f}{reset} - '
'Volume: {bold}฿{volume:,.2f}',
last=float(data['last']), high=float(data['high']),
low=float(data['low']), volume=float(data['volume']))