From 9b6d8d2dc0597d1a5717f3655ab49b4677e5bdec Mon Sep 17 00:00:00 2001 From: jesopo Date: Tue, 3 May 2016 11:58:42 +0100 Subject: [PATCH] added bitcoin.py. --- modules/bitcoin.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 modules/bitcoin.py diff --git a/modules/bitcoin.py b/modules/bitcoin.py new file mode 100644 index 00000000..17408322 --- /dev/null +++ b/modules/bitcoin.py @@ -0,0 +1,25 @@ +import Utils + +class Module(object): + _name = "BTC" + def __init__(self, bot): + self.bot = bot + bot.events.on("received").on("command").on("btc").hook( + self.btc, help="Get the exchange rate of bitcoins", + usage="[currency]") + + def btc(self, event): + currency = (event["args"] or "USD").upper() + page = Utils.get_url("https://blockchain.info/ticker", + json=True) + 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: + event["stderr"].write("Failed to load results")