Compare commits
4 Commits
f3c539ad78
...
4e3ea71437
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e3ea71437 | ||
|
|
812a463846 | ||
|
|
377ab13705 | ||
|
|
e828091c25 |
@ -18,7 +18,7 @@ class UEventParser(configparser.ConfigParser):
|
|||||||
return dict(parser.items("id10t"))
|
return dict(parser.items("id10t"))
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(default_section="id10t")
|
super().__init__(default_section="id10t", strict=False)
|
||||||
|
|
||||||
def optionxform(self, key):
|
def optionxform(self, key):
|
||||||
return lchop(key, "POWER_SUPPLY_")
|
return lchop(key, "POWER_SUPPLY_")
|
||||||
|
|||||||
@ -37,19 +37,7 @@ class Bitcoin(IntervalModule):
|
|||||||
.. rubric:: Available formatters
|
.. rubric:: Available formatters
|
||||||
|
|
||||||
* {last_price}
|
* {last_price}
|
||||||
* {ask_price}
|
|
||||||
* {bid_price}
|
|
||||||
* {open_price}
|
|
||||||
* {volume}
|
|
||||||
* {volume_thousand}
|
|
||||||
* {volume_percent}
|
|
||||||
* {age}
|
|
||||||
* {status}
|
* {status}
|
||||||
* {last_tx_type}
|
|
||||||
* {last_tx_addr}
|
|
||||||
* {last_tx_value}
|
|
||||||
* {balance_btc}
|
|
||||||
* {balance_fiat}
|
|
||||||
* {symbol}
|
* {symbol}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -57,9 +45,9 @@ class Bitcoin(IntervalModule):
|
|||||||
settings = (
|
settings = (
|
||||||
("format", "Format string used for output."),
|
("format", "Format string used for output."),
|
||||||
("currency", "Base fiat currency used for pricing."),
|
("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"),
|
("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"),
|
("colorize", "Enable color change on price increase/decrease"),
|
||||||
("color_up", "Color for price increases"),
|
("color_up", "Color for price increases"),
|
||||||
("color_down", "Color for price decreases"),
|
("color_down", "Color for price decreases"),
|
||||||
@ -69,7 +57,7 @@ class Bitcoin(IntervalModule):
|
|||||||
)
|
)
|
||||||
format = "{symbol} {status}{last_price}"
|
format = "{symbol} {status}{last_price}"
|
||||||
currency = "USD"
|
currency = "USD"
|
||||||
exchange = "bitstamp"
|
exchange = "blockchain.info"
|
||||||
symbol = "\uF15A"
|
symbol = "\uF15A"
|
||||||
wallet_addresses = ""
|
wallet_addresses = ""
|
||||||
color = "#FFFFFF"
|
color = "#FFFFFF"
|
||||||
@ -95,17 +83,14 @@ class Bitcoin(IntervalModule):
|
|||||||
return int(diff.total_seconds())
|
return int(diff.total_seconds())
|
||||||
|
|
||||||
def _query_api(self, api_url):
|
def _query_api(self, api_url):
|
||||||
url = "{}/{}".format(api_url, self.exchange.upper())
|
url = "{}".format(api_url)
|
||||||
response = urllib.request.urlopen(url).read().decode("utf-8")
|
response = urllib.request.urlopen(url).read().decode("utf-8")
|
||||||
return json.loads(response)
|
return json.loads(response)
|
||||||
|
|
||||||
def _fetch_price_data(self):
|
def _fetch_price_data(self):
|
||||||
api_url = "https://api.bitaps.com/market/v1/tickers"
|
api_url = "https://blockchain.info/ticker"
|
||||||
ret = self._query_api(api_url)["data"]
|
ret = self._query_api(api_url)
|
||||||
exchange = ret[self.exchange.upper()]["pairs"]["BTC{}".format(self.currency.upper())]
|
return ret[self.currency.upper()]
|
||||||
# Adapt values to global ticker format
|
|
||||||
exchange['24h_avg'] = None
|
|
||||||
return exchange
|
|
||||||
|
|
||||||
def _fetch_blockchain_data(self):
|
def _fetch_blockchain_data(self):
|
||||||
api = "https://blockchain.info/multiaddr?active="
|
api = "https://blockchain.info/multiaddr?active="
|
||||||
@ -119,13 +104,7 @@ class Bitcoin(IntervalModule):
|
|||||||
|
|
||||||
fdict = {
|
fdict = {
|
||||||
"symbol": self.symbol,
|
"symbol": self.symbol,
|
||||||
"open": price_data["open"],
|
"last_price": float(price_data["last"]),
|
||||||
"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:
|
if self._price_prev and fdict["last_price"] > self._price_prev:
|
||||||
@ -142,26 +121,6 @@ class Bitcoin(IntervalModule):
|
|||||||
if not self.colorize:
|
if not self.colorize:
|
||||||
color = self.color
|
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.data = fdict
|
||||||
self.output = {
|
self.output = {
|
||||||
"full_text": self.format.format(**fdict),
|
"full_text": self.format.format(**fdict),
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from i3pystatus import IntervalModule
|
from i3pystatus import IntervalModule
|
||||||
@ -62,7 +63,7 @@ class Ping(IntervalModule):
|
|||||||
def ping_host(self):
|
def ping_host(self):
|
||||||
p = subprocess.Popen(["ping", "-c1", "-w%d" % self.interval,
|
p = subprocess.Popen(["ping", "-c1", "-w%d" % self.interval,
|
||||||
self.host], stdout=subprocess.PIPE,
|
self.host], stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.DEVNULL)
|
stderr=subprocess.DEVNULL, env=dict(os.environ, LC_ALL="C"))
|
||||||
out, _ = p.communicate()
|
out, _ = p.communicate()
|
||||||
if p.returncode == 0:
|
if p.returncode == 0:
|
||||||
return float(out.decode().split("\n")[1]
|
return float(out.decode().split("\n")[1]
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
import os.path
|
||||||
import unittest
|
import unittest
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
@ -9,7 +10,7 @@ from i3pystatus.buds import Buds, BudsEqualizer, BudsPlacementStatus
|
|||||||
class TestBuds(unittest.TestCase):
|
class TestBuds(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.buds = Buds()
|
self.buds = Buds()
|
||||||
with open('test_buds.json', 'rb') as file:
|
with open(os.path.join(os.path.dirname(__file__), 'test_buds.json'), 'rb') as file:
|
||||||
self.payload = json.load(file)
|
self.payload = json.load(file)
|
||||||
|
|
||||||
@patch('i3pystatus.buds.run_through_shell')
|
@patch('i3pystatus.buds.run_through_shell')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user