def __init__(self, exchange_rate_file): self.invoice_rates = {} f = open(exchange_rate_file, 'r') for line in iter(f): (inv_code, inv_date, btc_czk) = line.rstrip().split(';') self.invoice_rates[inv_code] = \ ExchangeRate.new_for_update(inv_date, btc_czk) f.close()
rates[currency[CNB_API_CURRENCY_CODE]] = rate_float / amount usd_czk = rates['USD'] # fetch BTC/USD price - weighted average for the past 24 hours client = bitstamp.client.Public() ticker = client.ticker() btc_usd = Decimal(ticker['vwap']) btc_czk = usd_czk * btc_usd btc_czk_str = "%s" % btc_czk.quantize(Decimal('1e-2')) print "USD/CZK: %s; BTC/USD: %s; BTC/CZK: %s" % (usd_czk, btc_usd, btc_czk_str) try: req = RateRequest() today_str = date.today().strftime("%Y-%m-%d") req.append(ExchangeRate.new_for_update(today_str, btc_czk_str)) print "Sending: %s" % req response = req.put(settings.url, settings.user, settings.passwd) print "Received: %s" % response.content except Exception, e: print 'Error: %s' % e print(traceback.format_exc()) sys.exit(2)