From 7e8da7686c617a28ce1e9c0a416fbc58c4649504 Mon Sep 17 00:00:00 2001 From: 1m0d <30176323+1m0d@users.noreply.github.com> Date: Mon, 3 Dec 2018 12:38:41 +0100 Subject: [PATCH] add option to round coin price to set decimal point (#658) * add option to round coin price to set decimal point * import decimal --- i3pystatus/coin.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/i3pystatus/coin.py b/i3pystatus/coin.py index aa55a7f..9d6d6c0 100644 --- a/i3pystatus/coin.py +++ b/i3pystatus/coin.py @@ -1,5 +1,6 @@ import requests import json +from decimal import Decimal from i3pystatus import IntervalModule from i3pystatus.core.util import internet, require @@ -33,6 +34,7 @@ class Coin(IntervalModule): settings = ( ("format", "format string used for output."), ("coin", "cryptocurrency to fetch"), + ("decimal", "round coin price down to this decimal place"), ("currency", "fiat currency to show fiscal data"), ("symbol", "coin symbol"), ("interval", "update interval in seconds"), @@ -45,6 +47,7 @@ class Coin(IntervalModule): currency = "USD" interval = 600 status_interval = "24h" + decimal = 2 def fetch_data(self): response = requests.get("https://api.coinmarketcap.com/v1/ticker/{}/?convert={}".format(self.coin, self.currency)) @@ -74,7 +77,9 @@ class Coin(IntervalModule): symbols = dict(bitcoin='฿', ethereum='Ξ', litecoin='Ł', dash='Đ') if self.coin in symbols: fdict["symbol"] = symbols[self.coin] + fdict["status"] = self.set_status(float(fdict["percent_change_{}".format(self.status_interval)])) + fdict["price"] = str(round(Decimal(fdict["price"]), self.decimal)) self.data = fdict self.output = {"full_text": self.format.format(**fdict)}