#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import urllib2
import json
from decimal import Decimal
currency = 'EUR'
try:
response = urllib2.urlopen('http://data.mtgox.com/api/1/BTC%s/ticker' % currency)
except Exception, why:
print '[Error] Can not connect!', why
sys.exit()
data = json.loads(response.read())
bitcoin_cur_value = Decimal(data['return']['avg']['value'])
r = 1 / bitcoin_cur_value
while True:
user_input = raw_input('BTC: ')
if user_input:
bitcoin_amount = Decimal(user_input)
cur_amount = bitcoin_amount / r
print '%s: %.2f' % (currency, cur_amount)