Compare commits

..

No commits in common. "4e3ea71437dfb6a126ec9649e894bf3ba962918e" and "f3c539ad78ad1c54fc36e8439bf3905a784ccb34" have entirely different histories.

4 changed files with 52 additions and 13 deletions

View File

@ -18,7 +18,7 @@ class UEventParser(configparser.ConfigParser):
return dict(parser.items("id10t"))
def __init__(self):
super().__init__(default_section="id10t", strict=False)
super().__init__(default_section="id10t")
def optionxform(self, key):
return lchop(key, "POWER_SUPPLY_")

View File

@ -37,7 +37,19 @@ class Bitcoin(IntervalModule):
.. rubric:: Available formatters
* {last_price}
* {ask_price}
* {bid_price}
* {open_price}
* {volume}
* {volume_thousand}
* {volume_percent}
* {age}
* {status}
* {last_tx_type}
* {last_tx_addr}
* {last_tx_value}
* {balance_btc}
* {balance_fiat}
* {symbol}
"""
@ -45,9 +57,9 @@ class Bitcoin(IntervalModule):
settings = (
("format", "Format string used for output."),
("currency", "Base fiat currency used for pricing."),
# ("wallet_addresses", "List of wallet address(es) to monitor."),
("wallet_addresses", "List of wallet address(es) to monitor."),
("color", "Standard color"),
# ("exchange", "Get ticker from a custom exchange instead"),
("exchange", "Get ticker from a custom exchange instead"),
("colorize", "Enable color change on price increase/decrease"),
("color_up", "Color for price increases"),
("color_down", "Color for price decreases"),
@ -57,7 +69,7 @@ class Bitcoin(IntervalModule):
)
format = "{symbol} {status}{last_price}"
currency = "USD"
exchange = "blockchain.info"
exchange = "bitstamp"
symbol = "\uF15A"
wallet_addresses = ""
color = "#FFFFFF"
@ -83,14 +95,17 @@ class Bitcoin(IntervalModule):
return int(diff.total_seconds())
def _query_api(self, api_url):
url = "{}".format(api_url)
url = "{}/{}".format(api_url, self.exchange.upper())
response = urllib.request.urlopen(url).read().decode("utf-8")
return json.loads(response)
def _fetch_price_data(self):
api_url = "https://blockchain.info/ticker"
ret = self._query_api(api_url)
return ret[self.currency.upper()]
api_url = "https://api.bitaps.com/market/v1/tickers"
ret = self._query_api(api_url)["data"]
exchange = ret[self.exchange.upper()]["pairs"]["BTC{}".format(self.currency.upper())]
# Adapt values to global ticker format
exchange['24h_avg'] = None
return exchange
def _fetch_blockchain_data(self):
api = "https://blockchain.info/multiaddr?active="
@ -104,7 +119,13 @@ class Bitcoin(IntervalModule):
fdict = {
"symbol": self.symbol,
"last_price": float(price_data["last"]),
"open": price_data["open"],
"ask_price": price_data["ask"],
"bid_price": price_data["bid"],
"last_price": price_data["last"],
"volume": price_data["volume"],
"volume_thousand": float(price_data["volume"]) / 1000,
"age": self._get_age(price_data['timestamp'])
}
if self._price_prev and fdict["last_price"] > self._price_prev:
@ -121,6 +142,26 @@ class Bitcoin(IntervalModule):
if not self.colorize:
color = self.color
if self.wallet_addresses:
blockchain_data = self._fetch_blockchain_data()
wallet_data = blockchain_data["wallet"]
balance_btc = wallet_data["final_balance"] / 100000000
fdict["balance_btc"] = round(balance_btc, 2)
balance_fiat = fdict["balance_btc"] * fdict["last_price"]
fdict["balance_fiat"] = round(balance_fiat, 2)
fdict["total_sent"] = wallet_data["total_sent"]
fdict["total_received"] = wallet_data["total_received"]
fdict["transactions"] = wallet_data["n_tx"]
if fdict["transactions"]:
last_tx = blockchain_data["txs"][0]
fdict["last_tx_addr"] = last_tx["out"][0]["addr"]
fdict["last_tx_value"] = last_tx["out"][0]["value"] / 100000000
if fdict["last_tx_addr"] in self.wallet_addresses:
fdict["last_tx_type"] = "recv"
else:
fdict["last_tx_type"] = "sent"
self.data = fdict
self.output = {
"full_text": self.format.format(**fdict),

View File

@ -1,4 +1,3 @@
import os
import subprocess
from i3pystatus import IntervalModule
@ -63,7 +62,7 @@ class Ping(IntervalModule):
def ping_host(self):
p = subprocess.Popen(["ping", "-c1", "-w%d" % self.interval,
self.host], stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL, env=dict(os.environ, LC_ALL="C"))
stderr=subprocess.DEVNULL)
out, _ = p.communicate()
if p.returncode == 0:
return float(out.decode().split("\n")[1]

View File

@ -1,5 +1,4 @@
import json
import os.path
import unittest
from copy import deepcopy
from unittest.mock import patch
@ -10,7 +9,7 @@ from i3pystatus.buds import Buds, BudsEqualizer, BudsPlacementStatus
class TestBuds(unittest.TestCase):
def setUp(self):
self.buds = Buds()
with open(os.path.join(os.path.dirname(__file__), 'test_buds.json'), 'rb') as file:
with open('test_buds.json', 'rb') as file:
self.payload = json.load(file)
@patch('i3pystatus.buds.run_through_shell')