-
Notifications
You must be signed in to change notification settings - Fork 3
/
miners.py
123 lines (93 loc) · 4.17 KB
/
miners.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
import subprocess
import requests
from requests.exceptions import HTTPError
import json
import sys
import time
from tabulate import tabulate
from operator import itemgetter
def format_hashrate(hr):
unit = ''
if hr < 1000:
unit = 'H'
elif hr < 1000000:
hr /= 1000
unit = 'kH'
else:
hr /= 1000000
unit = 'mH'
return '{:.2f} {}/s'.format(hr, unit)
def main():
subprocess.call("clear")
username = None
while not username:
username = input('Enter your DUCO username: ')
print("Fetching miners list…")
prev_balance = 0
last_update = None
while True:
try:
miners_response = requests.get(f"https://server.duinocoin.com/miners/{username}")
miners_response.raise_for_status()
miners_json_data = json.loads(miners_response.text)
balances_response = requests.get(f"https://server.duinocoin.com/balances/{username}")
balances_response.raise_for_status()
balances_json_data = json.loads(balances_response.text)
api_response = requests.get("https://server.duinocoin.com/api.json")
api_response.raise_for_status()
api_json_data = json.loads(api_response.text)
except HTTPError as http_err:
print(f'HTTP error occurred: {http_err}')
time.sleep(10)
continue
except Exception as err:
print(f'Other error occurred: {err}')
time.sleep(10)
continue
except KeyboardInterrupt:
print('Exiting…')
sys.exit()
if miners_json_data and balances_json_data and api_json_data:
subprocess.call("clear")
duco_price_usd = api_json_data.get('Duco price', 0)
#user_miners = [v for v in miners_json_data.values() if v["User"] == username]
user_miners = miners_json_data.get('result')
if not user_miners:
print("No miners found.")
miners = []
total_hash = 0
totalSharerate = 0
totalAccepted = 0
for v in user_miners:
hashrate = int(v.get("hashrate", 0))
total_hash += hashrate
accepted = int(v.get("accepted", 0))
rejected = int(v.get("rejected", 0))
sharerate = int(v.get("sharetime", 0))
if sharerate < (accepted + rejected):
sharerate = accepted + rejected
totalSharerate += sharerate
totalAccepted += accepted
successRate = f'{accepted}/{sharerate}'
algo = v["algorithm"]
diff = int(v.get("diff", 0))
id = v["identifier"]
software = v["software"]
miners.append([id, software, algo, successRate, format_hashrate(hashrate), diff])
miners.sort(key=itemgetter(0))
#user_balance_str = balances_json_data.get(username, "0 DUCO").replace(' DUCO', ' ᕲ')
#user_balance = float(user_balance_str.replace(' ᕲ', ''))
user_balance = balances_json_data.get('result').get('balance')
balance_difference = user_balance - prev_balance
time_difference = time.time() - last_update if last_update else 0
daily_average = balance_difference*float((60/time_difference)*60*24) if time_difference != 0 else 0
total_success_pc = int((totalAccepted/totalSharerate)*100) if totalSharerate > 0 else 0
total_success = f'{total_success_pc}% ({totalAccepted}/{totalSharerate})'
print(tabulate([[user_balance, len(miners), format_hashrate(total_hash), f'{total_success}', f'{daily_average} ᕲ']], headers=["Balance", "Total miners", "Total hashrate", "Total success", "Daily profit"]))
if miners:
print(tabulate(miners, headers=["ID", "Software", "Algo", "Success", "Hashrate", "Diff"], tablefmt='fancy_grid'))
prev_balance = user_balance
last_update = time.time()
time.sleep(15)
if __name__ == "__main__":
main()