Skip to content

Instantly share code, notes, and snippets.

@Ell
Forked from anonymous/doge.py
Created January 21, 2014 06:56
Show Gist options
  • Save Ell/8535526 to your computer and use it in GitHub Desktop.
Save Ell/8535526 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)
usd = d[0]
btc = d[1]
return u'{0} DOGE is worth ${1:.2f} USD (1 DOGE : {2:.5f} BTC)'.format(amount, usd, btc)
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
if __name__ == "__main__":
print doge_to_usd()[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment