This repository has been archived on 2023-04-13. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
CloudBot/plugins/bitcoin.py
2013-11-12 18:49:29 +01:00

16 lines
750 B
Python
Executable file

from util import http, hook
@hook.command(autohelp=False)
def bitcoin(inp, message=None):
"""bitcoin -- gets current exchange rate for bitcoins from mtgox"""
data = http.get_json("https://data.mtgox.com/api/2/BTCUSD/money/ticker")
data = data['data']
ticker = {
'buy': data['buy']['display_short'].encode('ascii', 'ignore'),
'high': data['high']['display_short'].encode('ascii', 'ignore'),
'low': data['low']['display_short'].encode('ascii', 'ignore'),
'vol': data['vol']['display_short'].encode('ascii', 'ignore'),
}
message("Current: \x0307{!s}\x0f - High: \x0307{!s}\x0f"
" - Low: \x0307{!s}\x0f - Volume: {!s}".format(ticker['buy'], ticker['high'], ticker['low'], ticker['vol']))