Browse Source

[ShortUtils] Add ability to get bitcoin price

master
Sfan5 8 years ago
parent
commit
55fd893da8
  1. 1
      COMMANDS.md
  2. 20
      shortutils.py

1
COMMANDS.md

@ -90,6 +90,7 @@ Required arguments are enclosed in { and }, optional arguments are enclosed in \
<tr> <td>!next</td> <td>Say: "Another satisfied customer. Next!"</td> <td>Anyone</td> </tr>
<tr> <td>!pil [nick]</td> <td>Link to Lua PIL</td> <td>Anyone</td> </tr>
<tr> <td>!git [nick]</td> <td>Link to Git manual</td> <td>Anyone</td> </tr>
<tr> <td>!btc [currency]</td> <td>Get Bitcoin price for specified currency</td> <td>Anyone</td> </tr>
<tr> <td><b>tell.py</b></td> <td></td> <td></td> </tr>
<tr> <td>!tell {nick} {message}</td> <td>Tell somebody a message</td> <td>Anyone</td> </tr>
</table>

20
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']

Loading…
Cancel
Save