PEP 8 (I'm bored): bitcoin

This commit is contained in:
enkore 2014-10-14 16:35:15 +02:00
parent f6e910c114
commit 54bae95804

View File

@ -10,11 +10,11 @@ class Bitcoin(IntervalModule):
""" """
This module fetches and displays current Bitcoin market prices and This module fetches and displays current Bitcoin market prices and
optionally monitors transactions to and from a list of user-specified optionally monitors transactions to and from a list of user-specified
wallet addresses. Market data is pulled from the BitcoinAverage Price wallet addresses. Market data is pulled from the BitcoinAverage Price
Index API <https://bitcoinaverage.com> while transaction data is pulled Index API <https://bitcoinaverage.com> while transaction data is pulled
from blockchain.info <https://blockchain.info/api/blockchain_api>. from blockchain.info <https://blockchain.info/api/blockchain_api>.
.. rubric:: Available formatters .. rubric:: Available formatters
* {last_price} * {last_price}
@ -65,14 +65,13 @@ class Bitcoin(IntervalModule):
api = "https://api.bitcoinaverage.com/ticker/global/" api = "https://api.bitcoinaverage.com/ticker/global/"
url = "{}{}".format(api, self.currency.upper()) url = "{}{}".format(api, self.currency.upper())
return json.loads(urllib.request.urlopen(url).read().decode("utf-8")) return json.loads(urllib.request.urlopen(url).read().decode("utf-8"))
def _fetch_blockchain_data(self): def _fetch_blockchain_data(self):
api = "https://blockchain.info/multiaddr?active=" api = "https://blockchain.info/multiaddr?active="
addresses = "|".join(self.wallet_addresses) addresses = "|".join(self.wallet_addresses)
url = "{}{}".format(api, addresses) url = "{}{}".format(api, addresses)
return json.loads(urllib.request.urlopen(url).read().decode("utf-8")) return json.loads(urllib.request.urlopen(url).read().decode("utf-8"))
@require(internet) @require(internet)
def run(self): def run(self):
price_data = self._fetch_price_data() price_data = self._fetch_price_data()
@ -98,10 +97,10 @@ class Bitcoin(IntervalModule):
if not self.colorize: if not self.colorize:
color = self.color color = self.color
if self.wallet_addresses: if self.wallet_addresses:
blockchain_data = self._fetch_blockchain_data() blockchain_data = self._fetch_blockchain_data()
wallet_data = blockchain_data["wallet"] wallet_data = blockchain_data["wallet"]
balance_btc = wallet_data["final_balance"]/100000000 balance_btc = wallet_data["final_balance"] / 100000000
fdict["balance_btc"] = round(balance_btc, 2) fdict["balance_btc"] = round(balance_btc, 2)
balance_fiat = fdict["balance_btc"] * fdict["last_price"] balance_fiat = fdict["balance_btc"] * fdict["last_price"]
fdict["balance_fiat"] = round(balance_fiat, 2) fdict["balance_fiat"] = round(balance_fiat, 2)
@ -112,7 +111,7 @@ class Bitcoin(IntervalModule):
if fdict["transactions"]: if fdict["transactions"]:
last_tx = blockchain_data["txs"][0] last_tx = blockchain_data["txs"][0]
fdict["last_tx_addr"] = last_tx["out"][0]["addr"] fdict["last_tx_addr"] = last_tx["out"][0]["addr"]
fdict["last_tx_value"] = last_tx["out"][0]["value"]/100000000 fdict["last_tx_value"] = last_tx["out"][0]["value"] / 100000000
if fdict["last_tx_addr"] in self.wallet_addresses: if fdict["last_tx_addr"] in self.wallet_addresses:
fdict["last_tx_type"] = "recv" fdict["last_tx_type"] = "recv"
else: else:
@ -125,6 +124,6 @@ class Bitcoin(IntervalModule):
def on_leftclick(self): def on_leftclick(self):
user_open(self.leftclick) user_open(self.leftclick)
def on_rightclick(self): def on_rightclick(self):
user_open(self.rightclick) user_open(self.rightclick)