I tried doing this but it still didnt work
```
class CryptoTicker(widget.CryptoTicker):
def fetch(self, url):
req = Request(url, self.data, self.headers)
res = urlopen(req)
charset = res.headers.get_content_charset()
body = res.read()
if charset:
body = body.decode(charset)
if self.json:
body = json.loads(body)
if self.xml:
body = xmlparse(body)
return body
def poll(self):
if not self.parse or not self.url:
return "Invalid config"
_, min = map(int, time.strftime("%H %M").split())
try:
body = self.fetch(
self.QUERY_URL.format(
self.cryptos[min % len(self.cryptos)], self.currency
)
)
except URLError:
return "No network"
try:
text = self.parse(body)
except Exception:
logger.exception("got exception polling widget")
text = "Can't parse"
return text
```
On Tuesday, 5 April 2022 at 16:43:00 UTC+1 [email protected] wrote:
> I'm trying to do something like this:
> ```
> class CryptoTicker(GenPollUrl):
>
> QUERY_URL = "https://api.coinbase.com/v2/prices/{}-{}/spot"
>
> defaults = [
> (
> "currency",
> "USD",
> "The baseline currency that the value of the crypto is
> displayed in.",
> ),
> ("symbol", "$", "The symbol for the baseline currency."),
> ("crypto", "BTC", "The cryptocurrency to display."),
> ("format", "{crypto}: {symbol}{amount:.2f}", "Display string
> formatting."),
> ]
>
> def __init__(self, **config):
> GenPollUrl.__init__(self, **config)
>
> _, min = map(int, time.strftime("%H %M").split())
>
> cryptos = [
> "BTC",
> "ETH",
> "ADA",
> "AVAX",
> ]
>
> self.currency = "USD"
> self.symbol = "$"
> self.crypto = cryptos[min % len(cryptos)]
> self.format = "{crypto}:{symbol}{amount:.2f}"
>
> @property
> def url(self):
> return self.QUERY_URL.format(self.crypto, self.currency)
>
> def parse(self, body):
> variables = dict()
> variables["crypto"] = self.crypto
> variables["symbol"] = self.symbol
> variables["amount"] = float(body["data"]["amount"])
>
> return self.format.format(**variables)
> ```
>
> It is stuck with one of the cryptos on the list instead of updating to the
> new one. Please advise thanks
>
--
You received this message because you are subscribed to the Google Groups
"qtile-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/qtile-dev/e9e0358e-57e3-4215-8567-e0c8dbef6217n%40googlegroups.com.