def _options_vpn(provider): name, _ = provider.get_metadata() print(("Options for %s:\n" % name)) options = provider.get_options() # Print heading row = "{:18}" * 6 print( row.format("Name", "Protocol", "Bandwidth", "Speed", "Est. Price (mBTC)", "Price (USD)")) for option in options: bandwidth = "Unlimited" if option.bandwidth == sys.maxsize else str( option.bandwidth) speed = "Unlimited" if option.speed == sys.maxsize else option.speed # Calculate the estimated price rate = wallet_util.get_rate("USD") fee = wallet_util.get_network_fee() gateway = provider.get_gateway() estimate = gateway.estimate_price(option.price * rate) + fee # BTC estimate = round(1000 * estimate, 2) # mBTC print( row.format(option.name, option.protocol, bandwidth, speed, str(estimate), str(option.price)))
def _options_vps(p): name, _ = p.get_metadata() print(("Options for %s:\n" % name)) options = p.get_options() # Print heading row = "{:<5}" + "{:20}" * 8 print( row.format("#", "Name", "Cores", "Memory (GB)", "Storage (GB)", "Bandwidth", "Connection (Gbit/s)", "Est. Price (mBTC)", "Price (USD)")) for i, option in enumerate(options): bandwidth = "Unlimited" if option.bandwidth == sys.maxsize else str( option.bandwidth) # Calculate the estimated price rate = wallet_util.get_rate("USD") fee = wallet_util.get_network_fee() gateway = p.get_gateway() estimate = gateway.estimate_price(option.price * rate) + fee # BTC estimate = round(1000 * estimate, 2) # mBTC print( row.format(i, option.name, str(option.cores), str(option.memory), str(option.storage), bandwidth, str(option.connection), str(estimate), str(option.price)))
def pay(self, wallet, url): self._browser.open(url) soup = self._browser.get_current_page() address = soup.select_one("div.transaction > input").get("value") amount = float(soup.select_one("div.transaction > input:nth-of-type(2)").get("value")) fee = wallet_util.get_network_fee() print(('Calculated fee: %s' % fee)) transaction_hash = wallet.pay(address, amount, fee) print('Done purchasing') return transaction_hash
def pay(cls, wallet, gateway, url): """Do a payment (should be moved to the payment gateways?) :param wallet: the wallet to pay with :param gateway: gateway through which to make the payment :param url: url from which the amount and address can be extracted """ name, _ = cls.get_metadata() # Make the payment print("Purchasing {} instance".format(name)) info = gateway.extract_info(url) print(('Paying %s BTC to %s' % (info.amount, info.address))) fee = wallet_util.get_network_fee() print(('Calculated fee: %s' % fee)) transaction_hash = wallet.pay(info.address, info.amount, fee) print('Done purchasing') return transaction_hash
def get_network_fee(): return wallet_util.get_network_fee()