blob: c130d20dff93981f1f8b6e6d4510c27433b3e7c7 (
about) (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#--depends-on commands
from src import ModuleManager, utils
class Module(ModuleManager.BaseModule):
_name = "BTC"
@utils.hook("received.command.btc")
def btc(self, event):
"""
:help: Get the exchange rate of bitcoins
:usage: [currency]
"""
currency = (event["args"] or "USD").upper()
page = utils.http.request("https://blockchain.info/ticker").json()
if page:
if currency in page:
conversion = page[currency]
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 "
"currencies: %s" % ", ".join(page.keys()))
else:
raise utils.EventResultsError()
|