Skip to content

Instantly share code, notes, and snippets.

Created January 21, 2014 06:38
Show Gist options
  • Save anonymous/8535372 to your computer and use it in GitHub Desktop.
Save anonymous/8535372 to your computer and use it in GitHub Desktop.
from util import hook
import requests
from decimal import Decimal
@hook.command
def doge(inp, say=None):
try:
amount = int(inp)
except:
amount = 1000
d = doge_to_usd(amount)
return u'{0} DOGE is worth ${1:.2f} USD (1 DOGE : {2:.8f} BTC)'.format(amount, d[0], d[1])
def doge_to_usd(amount=1000):
doge = Decimal(doge_to_btc())
usd = Decimal(btc_to_usd())
if doge:
return (amount * (doge * usd), doge * usd)
else:
return "Cryptsy API is shitting itself. Try again in a lil bit."
def btc_to_usd():
data = requests.get('https://data.mtgox.com/api/2/BTCUSD/money/ticker').json()
return data['data']['buy']['display_short'].replace("$", "")
def doge_to_btc():
market_id = "132"
url = "https://www.cryptsy.com/trades/ajaxlasttrades"
try:
data = requests.get(url).json()
return data['132']
except:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment