2019-05-25 20:40:06 +00:00
|
|
|
#--depends-on commands
|
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
from src import ModuleManager, utils
|
2016-05-03 10:58:42 +00:00
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
class Module(ModuleManager.BaseModule):
|
2016-05-03 10:58:42 +00:00
|
|
|
_name = "BTC"
|
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.btc")
|
2016-05-03 10:58:42 +00:00
|
|
|
def btc(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Get the exchange rate of bitcoins
|
|
|
|
:usage: [currency]
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2016-05-03 10:58:42 +00:00
|
|
|
currency = (event["args"] or "USD").upper()
|
2018-12-11 22:26:38 +00:00
|
|
|
page = utils.http.request("https://blockchain.info/ticker",
|
2016-05-03 10:58:42 +00:00
|
|
|
json=True)
|
|
|
|
if page:
|
2018-12-11 22:26:38 +00:00
|
|
|
if currency in page.data:
|
|
|
|
conversion = page.data[currency]
|
2016-05-03 10:58:42 +00:00
|
|
|
buy, sell = conversion["buy"], conversion["sell"]
|
|
|
|
event["stdout"].write("1 BTC = %.2f %s (buy) %.2f %s "
|
|
|
|
"(sell)" % (buy, currency, sell, currency))
|
|
|
|
else:
|
|
|
|
event["stderr"].write("Unknown currency, available "
|
2018-12-11 22:26:38 +00:00
|
|
|
"currencies: %s" % ", ".join(page.data.keys()))
|
2016-05-03 10:58:42 +00:00
|
|
|
else:
|
2019-11-18 12:06:59 +00:00
|
|
|
raise utils.EventResultsError()
|