magic?
This commit is contained in:
parent
13c7e5915b
commit
1ecdd3a246
1 changed files with 33 additions and 11 deletions
|
@ -1,19 +1,41 @@
|
||||||
from util import http, hook
|
from util import http, hook
|
||||||
|
|
||||||
|
|
||||||
|
@hook.command("btc", autohelp=False)
|
||||||
@hook.command(autohelp=False)
|
@hook.command(autohelp=False)
|
||||||
def bitcoin(inp, message=None):
|
def bitcoin(inp):
|
||||||
"""bitcoin -- gets current exchange rate for bitcoins from mtgox"""
|
"bitcoin <exchange> -- Gets current exchange rate for bitcoins from several exchanges, default is MtGox. Supports MtGox, Bitpay, and BitStamp."
|
||||||
data = http.get_json("https://data.mtgox.com/api/2/BTCUSD/money/ticker")
|
exchanges = {
|
||||||
data = data['data']
|
"mtgox": {
|
||||||
ticker = {
|
"api_url": "https://mtgox.com/api/1/BTCUSD/ticker",
|
||||||
'buy': data['buy']['display_short'].encode('ascii', 'ignore'),
|
"func": lambda data: u"\x02MtGox\x02 // Current: {}, High: {}, Low: {}, Best Ask: {}, Volume: {}".format(data['return']['last']['display'], \
|
||||||
'high': data['high']['display_short'].encode('ascii', 'ignore'),
|
data['return']['high']['display'], data['return']['low']['display'], data['return']['buy']['display'], \
|
||||||
'low': data['low']['display_short'].encode('ascii', 'ignore'),
|
data['return']['vol']['display'])
|
||||||
'vol': data['vol']['display_short'].encode('ascii', 'ignore'),
|
},
|
||||||
|
"bitpay": {
|
||||||
|
"api_url": "https://bitpay.com/api/rates",
|
||||||
|
"func": lambda data: u"\x02Bitpay\x02 // Current: ${}".format(data[0]['rate'])
|
||||||
|
},
|
||||||
|
"bitstamp": {
|
||||||
|
"api_url": "https://www.bitstamp.net/api/ticker/",
|
||||||
|
"func": lambda data: u"\x02BitStamp\x02 // Current: ${}, High: ${}, Low: ${}, Volume: {:.2f} BTC".format(data['last'], data['high'], data['low'], \
|
||||||
|
float(data['volume']))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
message("Current: \x0307{!s}\x0f - High: \x0307{!s}\x0f"
|
|
||||||
" - Low: \x0307{!s}\x0f - Volume: {!s}".format(ticker['buy'], ticker['high'], ticker['low'], ticker['vol']))
|
inp = inp.lower()
|
||||||
|
|
||||||
|
if inp:
|
||||||
|
if inp in exchanges:
|
||||||
|
exchange = exchanges[inp]
|
||||||
|
else:
|
||||||
|
return "Invalid Exchange"
|
||||||
|
else:
|
||||||
|
exchange = exchanges["mtgox"]
|
||||||
|
|
||||||
|
data = http.get_json(exchange["api_url"])
|
||||||
|
func = exchange["func"]
|
||||||
|
return func(data)
|
||||||
|
|
||||||
|
|
||||||
@hook.command(autohelp=False)
|
@hook.command(autohelp=False)
|
||||||
|
|
Reference in a new issue