-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstart.py
More file actions
61 lines (51 loc) · 2.11 KB
/
start.py
File metadata and controls
61 lines (51 loc) · 2.11 KB
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
__author__ = 'wuqingyi22@gmail.com'
import time
import json
import subprocess
import scraping
import logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s [%(levelname)s] - %(message)s',
filename='runtime.log'
)
logger = logging.getLogger()
zpool = scraping.Zpool('rig_zpool.json', 'algos_zpool.json')
mph = scraping.MiningPoolHub('rig_mph.json', 'algos_zpool.json')
mph.updateProfit()
current_algo = {}
while True:
logger.info('Start scraping')
mph.updateProfit()
zpool_top = zpool.getTopProfit() # get top algo
mph_top = mph.getTopAlgo()
while not zpool_top and not mph_top:
logger.warning('Scraping failed, wait 10 minutes and retry')
time.sleep(600)
zpool_top = zpool.getTopProfit() # if getTopProfit returns False, wait 10 minutes and retry
mph_top = mph.getTopAlgo()
logger.info(zpool_top)
logger.info(mph_top)
if current_algo:
process.kill() # kill current miner, it doesn't hurt
logger.info('Killing current miner')
time.sleep(5)
if zpool_top['profit'] >= 1.2 * mph_top['profit']: # prefer MPH over zpool
current_algo = zpool_top
else:
current_algo = mph_top
mph.resetProfit()
# start new mining process
mining_cmd = [current_algo['miner'], '-a', current_algo['algo'], '-o',
current_algo['stratum'], '-u', current_algo['user'],
'-p', current_algo['password']]
logger.info(' '.join([str(item) for item in mining_cmd]))
process = subprocess.Popen([current_algo['miner'], '-a', current_algo['algo'], '-o', current_algo['stratum'],
'-u', current_algo['user'], '-p', current_algo['password']])
timer = 0
while timer < mph.top_algo['switch_interval'] / mph.top_algo['fetch_interval']:
timer += 1
if process.poll() == 0: # if mining process dies, break wait loop and start next one
break
mph.updateProfit() # poll MPH to update current algo profits
time.sleep(mph.top_algo['fetch_interval']*60)