def priceimgadv(): """Serve the image, with advanced options. The StringIO trick is from here: http://stackoverflow.com/a/10170635/576932 """ price_string = request.args.get('price') output_currency = request.args.get('currency', 'BTC').upper() color_string = request.args.get('color', '0') try: price, input_currency = util.parse_price(price_string) except ValueError: return "Error: bad price argument" try: color = util.parse_color(color_string) except ValueError: return "Error: bad color argument" try: exchange_rate = util.get_exchange_rate(input_currency, output_currency) except KeyError: return 'Error: unsupported currency pair - %s -> %s' % (input_currency, output_currency) except Exception: return 'Error: exchange rate error' output_price = price * exchange_rate img_io = util.get_image_io(output_price, output_currency, color) return send_file(img_io, attachment_filename='img.png')
def priceimg(price_usd=None, color='0'): """Serve the image. The StringIO trick is from here: http://stackoverflow.com/a/10170635/576932 """ try: price_usd = float(price_usd) except ValueError: return "Error: bad USD price argument" try: color = util.parse_color(color) except ValueError: return "Error: bad color argument" try: btc_per_usd = util.get_exchange_rate('USD', 'BTC') except Exception: return "Error: exchange rate error" price_btc = price_usd * btc_per_usd img_io = util.get_image_io(price_btc, 'BTC', color) return send_file(img_io, attachment_filename='img.png')
def priceimgadv(): """Serve the image, with advanced options. The StringIO trick is from here: http://stackoverflow.com/a/10170635/576932 """ price_string = request.args.get('price') output_currency = request.args.get('currency', 'BTC').upper() color_string = request.args.get('color', '0') try: price, input_currency = util.parse_price(price_string) except ValueError: return "Error: bad price argument" try: color = util.parse_color(color_string) except ValueError: return "Error: bad color argument" try: exchange_rate = util.get_exchange_rate(input_currency, output_currency) except KeyError: return 'Error: unsupported currency pair - %s -> %s' % ( input_currency, output_currency) except Exception: return 'Error: exchange rate error' output_price = price * exchange_rate img_io = util.get_image_io(output_price, output_currency, color) return send_file(img_io, attachment_filename='img.png')
def balimg(dpr='1x', address=None, color='0'): """Serve image with address balance.""" try: balance = float(util.get_balance(address)) except ValueError: return "Error: bad address argument" except Exception: return 'Error: Blockchain.info error' try: color = util.parse_color(color) except ValueError: return "Error: bad color argument" try: dpr = float(dpr.rstrip('x')) except Exception: return 'Error: bad dpr argument' if dpr > MAX_DPR: return 'Error: maximum dpr is %d' % MAX_DPR if dpr <= 0: return 'Error: dpr must be greater than 0' img_io = util.get_image_io(dpr, balance, 'BTC', color) return send_file(img_io, attachment_filename='img.png')
def balimg(address=None, color='0'): """Serve image with address balance.""" try: address = float(util.get_balance(address)) except: return "Error: bad address argument" try: color = util.get_color(color) except: return "Error: bad color argument" img_io = util.get_image_io(address, 'BTC', color) return send_file(img_io, attachment_filename='img.png')
def balimg(address=None, color='0'): """Serve image with address balance.""" try: balance = float(util.get_balance(address)) except ValueError: return "Error: bad address argument" except Exception: return 'Error: Blockchain.info error' try: color = util.parse_color(color) except ValueError: return "Error: bad color argument" img_io = util.get_image_io(balance, 'BTC', color) return send_file(img_io, attachment_filename='img.png')
def priceimgadv(): """Serve the image, with advanced options. The StringIO trick is from here: http://stackoverflow.com/a/10170635/576932 """ price_string = request.args.get('price') output_currency = request.args.get('currency', 'BTC').upper() color_string = request.args.get('color', '0') dpr_string = request.args.get('dpr', '1x') try: price, input_currency = util.parse_price(price_string) except Exception: return 'Error: bad price argument' try: color = util.parse_color(color_string) except Exception: return 'Error: bad color argument' try: dpr = float(dpr_string.rstrip('x')) except Exception: return 'Error: bad dpr argument' if dpr > MAX_DPR: return 'Error: maximum dpr is %d' % MAX_DPR if dpr <= 0: return 'Error: dpr must be greater than 0' try: exchange_rate = util.get_exchange_rate(input_currency, output_currency) except KeyError: return 'Error: unsupported currency pair - %s -> %s' % ( input_currency, output_currency) except Exception: return 'Error: exchange rate error' output_price = price * exchange_rate img_io = util.get_image_io(dpr, output_price, output_currency, color) return send_file(img_io, attachment_filename='img.png')
def priceimgadv(): """Serve the image, with advanced options. The StringIO trick is from here: http://stackoverflow.com/a/10170635/576932 """ price_string = request.args.get('price') output_currency = request.args.get('currency', 'BTC').upper() color_string = request.args.get('color', '0') dpr_string = request.args.get('dpr', '1x') try: price, input_currency = util.parse_price(price_string) except Exception: return 'Error: bad price argument' try: color = util.parse_color(color_string) except Exception: return 'Error: bad color argument' try: dpr = float(dpr_string.rstrip('x')) except Exception: return 'Error: bad dpr argument' if dpr > MAX_DPR: return 'Error: maximum dpr is %d' % MAX_DPR if dpr <= 0: return 'Error: dpr must be greater than 0' try: exchange_rate = util.get_exchange_rate(input_currency, output_currency) except KeyError: return 'Error: unsupported currency pair - %s -> %s' % (input_currency, output_currency) except Exception: return 'Error: exchange rate error' output_price = price * exchange_rate img_io = util.get_image_io(dpr, output_price, output_currency, color) return send_file(img_io, attachment_filename='img.png')
def priceimgadv(): """Serve the image, with advanced options. The StringIO trick is from here: http://stackoverflow.com/a/10170635/576932 """ price_usd = request.args.get('price') currency = request.args.get('currency', 'BTC').upper() color = request.args.get('color', '0') try: price_usd = float(price_usd) except: return "Error: bad USD price argument" try: color = util.get_color(color) except: return "Error: bad color argument" if currency == 'BTC': try: usd_per_coin = util.get_usd_per_btc() except: return "Error: Mt Gox error" elif currency == 'LTC': try: usd_per_coin = util.get_usd_per_ltc() except: return 'Error: BTC-e error' else: return 'Error: unsupported currency: ' + currency price = price_usd / usd_per_coin img_io = util.get_image_io(price, currency, color) return send_file(img_io, attachment_filename='img.png')
def priceimg(dpr='1x', price_usd=None, color='0'): """Serve the image. The StringIO trick is from here: http://stackoverflow.com/a/10170635/576932 """ try: price_usd = float(price_usd) except ValueError: return 'Error: bad USD price argument' try: color = util.parse_color(color) except ValueError: return 'Error: bad color argument' try: dpr = float(dpr.rstrip('x')) except Exception: return 'Error: bad dpr argument' if dpr > MAX_DPR: return 'Error: maximum dpr is %d' % MAX_DPR if dpr <= 0: return 'Error: dpr must be greater than 0' try: btc_per_usd = util.get_exchange_rate('USD', 'BTC') except Exception: return "Error: exchange rate error" price_btc = price_usd * btc_per_usd img_io = util.get_image_io(dpr, price_btc, 'BTC', color) return send_file(img_io, attachment_filename='img.png')