def get_btc_amount(self, user, company): """ This method should be used when paying, otherwise get amount from self.total_btc """ datetime_updated_with_offset = self.datetime_updated + datetime.timedelta(hours=int(settings.PAYMENT_OFFICER["bitcoin_payment_waiting_interval"])) if self.status == WAITING: if self.total_btc is None or datetime_updated_with_offset < datetime.datetime.now(): currency = get_company_value(user, company, 'pos_currency') btc_price = calculate_btc_price(currency, self.total) if btc_price != -1: self.total_btc = btc_price self.save() return self.total_btc
import os import django from payment.service.Bitcoin import BitcoinRPC import settings django.setup() from common.functions import calculate_btc_price if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "webpos.settings") btc_price = calculate_btc_price("EUR", 0.5) print btc_price bitcoin_rpc = BitcoinRPC(settings.PAYMENT['bitcoin']['host'], settings.PAYMENT['bitcoin']['port'], settings.PAYMENT['bitcoin']['rpcuser'], settings.PAYMENT['bitcoin']['rpcpassword']) address = bitcoin_rpc.get_new_address("rokj_text")