From 55fd893da809007e1500202d95e25688fb3ffc33 Mon Sep 17 00:00:00 2001 From: Sfan5 Date: Thu, 27 Feb 2014 19:43:29 +0100 Subject: [PATCH] [ShortUtils] Add ability to get bitcoin price --- COMMANDS.md | 1 + shortutils.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/COMMANDS.md b/COMMANDS.md index 6bc52b8..ec3f3b0 100644 --- a/COMMANDS.md +++ b/COMMANDS.md @@ -90,6 +90,7 @@ Required arguments are enclosed in { and }, optional arguments are enclosed in \ !next Say: "Another satisfied customer. Next!" Anyone !pil [nick] Link to Lua PIL Anyone !git [nick] Link to Git manual Anyone + !btc [currency] Get Bitcoin price for specified currency Anyone tell.py !tell {nick} {message} Tell somebody a message Anyone diff --git a/shortutils.py b/shortutils.py index 2469b0f..3e6bd0f 100644 --- a/shortutils.py +++ b/shortutils.py @@ -124,4 +124,24 @@ def doge(phenny, input): doge.commands = ['doge'] +def btc(phenny, input): + """Get current Bitcoin price""" + for x in phenny.bot.commands["high"].values(): + if x[0].__name__ == "aa_hook": + if x[0](phenny, input): + return + f = urllib2.urlopen('https://blockchain.info/ticker') + data = f.read() + f.close() + data = json.loads(data) + if input.group(2): + currency = input.group(2).strip().upper() + else: + currency = 'USD' + if not currency in data.keys(): + return phenny.reply('Unknown currency. Supported currencies: ' + ', '.join(data.keys())) + phenny.say('1 BTC = %.4f %s' % (data[currency]['15m'], data[currency]['symbol'])) + +btc.commands = ['btc'] +