Source code for libqtile.widget.bitcoin_ticker

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from . import base
import json
import locale

from six.moves.urllib.request import urlopen

[docs]class BitcoinTicker(base.ThreadedPollText): ''' A bitcoin ticker widget, data provided by the API. Defaults to displaying currency in whatever the current locale is. ''' QUERY_URL = "" defaults = [ ('currency', locale.localeconv()['int_curr_symbol'].strip(), 'The currency the value of bitcoin is displayed in'), ('format', 'BTC Buy: {buy}, Sell: {sell}', 'Display format, allows buy, sell, high, low, avg, ' 'vol, vol_cur, last, variables.'), ] def __init__(self, **config): base.ThreadedPollText.__init__(self, **config) self.add_defaults(BitcoinTicker.defaults) def poll(self): res = urlopen(self.QUERY_URL % self.currency.lower()) formatted = {} res = json.loads( if 'error' in res and res['error'] == "invalid pair": locale.setlocale(locale.LC_MONETARY, "en_US.UTF-8") self.currency = locale.localeconv()['int_curr_symbol'].strip() res = urlopen(self.QUERY_URL % self.currency.lower()) res = json.loads( for k, v in res['ticker'].items(): formatted[k] = locale.currency(v) return self.format.format(**formatted)