-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcloudminingstatus.py
180 lines (152 loc) · 5.86 KB
/
cloudminingstatus.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
'''
cloudminingstatus.py
@summary: Show selected API data from cloudhasher and miningpool.
@author: Andreas Krueger
@since: 12 Feb 2017
@contact: https://github.com/drandreaskrueger
@copyright: @author @since @license
@license: Donationware, see README.md. Plus see LICENSE.
@version: v0.1.0
@status: It is working well.
@todo: Make it into webservice?
'''
from __future__ import print_function
import time
import sys
import pprint
import requests # pip install requests
SLEEP_SECONDS= 5*60
SHOW_COMPOSITE_RESULTS = True
try:
from credentials_ME import POOL_API_USERNAME, HASHER_API_ID, HASHER_API_KEY
except:
from credentials import POOL_API_USERNAME, HASHER_API_ID, HASHER_API_KEY
POOL_API_URL="http://soil.miners-zone.net/apisoil/accounts/%s"
HASHER_ORDERS_API_URL="https://www.nicehash.com/api?method=orders.get&my&algo=20&location=0&id=%s&key=%s"
HASHER_BALANCE_API_URL="https://www.nicehash.com/api?method=balance&id=%s&key=%s" # unused
def humanTime(epoch):
return time.strftime("GMT %H:%M:%S %a %d %b %Y", time.gmtime(epoch))
POOL_JSON=[('currentHashrate', (lambda x: "%6.2f MHash/s 30m average" % (x/1000000.0))),
('hashrate' , (lambda x: "%6.2f MHash/s 3h average" % (x/1000000.0))),
('paymentsTotal' , (lambda x:x)),
('stats' , (lambda x: "%10.4f SOIL paid" % (float(x['paid'])/1000000000))),
('stats' , (lambda x: "%10.4f SOIL balance" % (float(x['balance'])/1000000000))),
('24hreward',(lambda x: "%10.4f SOIL" % (float(x)/1000000000))),
('stats' , (lambda x: "%d blocksFound" % (x['blocksFound']))),
('stats' , (lambda x: "%s lastShare" % (humanTime(x['lastShare'])))),
('workers' , (lambda x: "%s last beat" % (humanTime(x['0']['lastBeat'])))),
('workers' , (lambda x: "%s Online" % (not bool(x['0']['offline'])))),
('workersTotal', (lambda x:x)),
]
HASHER_JSON_PATH=('result', 'orders', 0)
HASHER_JSON=[
('alive', (lambda x: x)),
('workers', (lambda x: x)),
('id', (lambda x: x)),
('pool_host', (lambda x: x)),
('pool_user', (lambda x: x)),
('limit_speed', (lambda x: "%6.2f MHash/s" % (float(x)*1000))),
('accepted_speed', (lambda x: "%6.2f MHash/s" % (float(x)*1000))),
('btc_paid', (lambda x: x)),
('btc_avail', (lambda x: x)),
('price', (lambda x: "%s BTC/GH/Day" % x)),
('end', (lambda x: "%4.2f days order lifetime" % (x/1000.0/60/60/24))),
]
def getJsonData(url):
"""
get url, check for status_code==200, return as json
"""
try:
r=requests.get(url)
except Exception as e:
print ("no connection: ", e)
return False
if r.status_code != 200:
print ("not answered OK==200, but ", r.status_code)
return False
try:
j=r.json()
except Exception as e:
print ("no json, text:")
print (r.text)
# raise e
return False
return j
def showPoolData(url):
"""
gets all json data from pool, but shows only what is in POOL_JSON
"""
print ("Pool:")
j=getJsonData(url)
if not j:
return False
# pprint.pprint (j)
for Jkey, Jfn in POOL_JSON:
print (Jfn(j[Jkey]), "(%s)" % Jkey)
return j
def showHasherData(url):
"""
gets all json data from cloudhasher, but shows only what is in HASHER_JSON
"""
print ("CloudHasher:")
j=getJsonData(url)
if not j:
return False
# pprint.pprint (j)
# climb down into the one branch with all the interesting data:
j=j [HASHER_JSON_PATH[0]] [HASHER_JSON_PATH[1]] [HASHER_JSON_PATH[2]]
# pprint.pprint (j)
for Jkey, Jfn in HASHER_JSON:
print (Jfn(j[Jkey]), "(%s)" % Jkey)
estimate = (float(j['btc_avail']) / ( float(j['price'])*float(j['accepted_speed'])) )
print ("%.2f days" % estimate, end='')
print ("(remaining btc / order price / hashrate)")
return j
def showCompositeResults(pooldata, hasherdata):
"""
Estimates a coin prices by money spent versus money mined.
N.B.: In this form probably only be roughly correct
during first buy order? We'll see.
"""
coinsMined = float(pooldata['stats']['paid'])
coinsMined += float(pooldata['stats']['balance'])
coinsMined /= 1000000000
hashingCostsBtc = float(hasherdata['btc_paid'])
satoshiPrice = hashingCostsBtc / coinsMined * 100000000
print ("%.1f Satoshi/SOIL (mining price approx)" % satoshiPrice)
return satoshiPrice
def loop(sleepseconds):
"""
Shows both, then sleeps, the repeats.
"""
while True:
print ()
pooldata=showPoolData(url=POOL_API_URL%POOL_API_USERNAME)
print ()
hasherdata=showHasherData(url=HASHER_ORDERS_API_URL%(HASHER_API_ID, HASHER_API_KEY))
print ()
if SHOW_COMPOSITE_RESULTS and pooldata and hasherdata:
showCompositeResults(pooldata, hasherdata)
print ()
print (humanTime(time.time()), end='')
print ("... sleep %s seconds ..." % sleepseconds)
time.sleep(sleepseconds)
def checkCredentials():
"""
See credentials.py
"""
yourCredentials=(POOL_API_USERNAME, HASHER_API_ID, HASHER_API_KEY)
if "" in yourCredentials:
print ("You must fill in credentials.py first.")
print (yourCredentials)
return False
else:
return True
if __name__ == '__main__':
if not checkCredentials():
sys.exit()
try:
loop(sleepseconds=SLEEP_SECONDS)
except KeyboardInterrupt:
print ("Bye.")
sys.exit()