-
Notifications
You must be signed in to change notification settings - Fork 2
/
status_build.py
executable file
·62 lines (52 loc) · 1.93 KB
/
status_build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from market_cap_api import get_coin_price
from pool_api import get_coin_balance, get_hashrate
from etherscan_api import get_wallet_balance
from blockchain_api import get_wallet_balance as btc_balance
from utils import print_json, is_number
import json
def usd_value(coin):
balance = get_coin_balance(coin)
price = get_coin_price(coin)
if isinstance(balance, (int, float)) and isinstance(price, (int, float)):
return round(balance * price, 2)
else:
return None
def build_status():
status = []
coins = ["ethereum", "bitcoin", "monacoin", "zclassic"]
functions = {
"balance": get_coin_balance,
"hashrate": get_hashrate,
"price": get_coin_price,
"USD value": usd_value
}
for c in coins:
coin_status = []
for f in functions:
coin_status.append(get_status("{}".format(f), functions[f](c)))
#call specific one off functions by coin
if c=="ethereum":
wallet_balance=get_wallet_balance()
coin_status.append(get_status("wallet balance", wallet_balance ))
coin_status.append(get_status("wallet USD", round(wallet_balance*get_coin_price(c),2)))
if c=="bitcoin":
wallet_balance = btc_balance()
coin_price = get_coin_price(c)
if wallet_balance is not None and is_number(coin_price):
coin_status.append(get_status("wallet balance", wallet_balance))
coin_status.append(get_status("wallet USD", round(wallet_balance * coin_price, 2)))
else:
print("bitcoin balance result was {}".format(wallet_balance))
status.append({
"coin":c,
"state":coin_status
})
return status
def get_status(status, status_value):
return {
"status": status,
"status_value": status_value
}
if __name__ == "__main__":
for i in build_status():
print_json(json.dumps(i))