-
Notifications
You must be signed in to change notification settings - Fork 0
/
mineschwifty.py
executable file
·74 lines (62 loc) · 2.18 KB
/
mineschwifty.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
#!/usr/bin/python
from __future__ import print_function
import yaml
import requests
f = open('mineschwifty.yml')
config = yaml.safe_load(f)
# state file. contains the key of the current coin
s = open(config['statefilename'], 'a+')
s.seek(0)
current_state = s.read()
s.close()
if current_state == '':
current_state = 'nothing'
sortbuffer_val = 0
sortbuffer_key = ''
def escalate(message):
#todo: bullet message? email?
print('ESC: %s'%(message))
def control_miner(coin, command):
print('EXEC: %s'%(config['coins'][coin][command]))
#exec(config['coins'][coin][command]);
def get_profit_index(key, coin):
"""sort the coin by profit"""
global sortbuffer_key, sortbuffer_val
# hack-adi-hack, das dollarsign muss weg :-)
profit_val = float(coin['profit'][1:])
if profit_val > sortbuffer_val:
sortbuffer_key = key
sortbuffer_val = profit_val
return sortbuffer_key, sortbuffer_val
for i in (config['coins']):
params = dict(
hr=config['coins'][i]['hashrate'],
p=config['coins'][i]['powerwall'],
cost=config['powercost']
)
try:
resp = requests.get(url=config.get('url')+str(config['coins'][i]['index'])+'.json', params=params)
get_profit_index(i, resp.json())
except Exception as e:
escalate('warning: failed to fetch wtm-data for %s (%s).'%(i,str(e)))
if sortbuffer_key != current_state:
print(sortbuffer_key, sortbuffer_val)
#if we know the current miner, we stop it
if current_state in config['coins']:
control_miner(current_state,'command_stop')
else:
#try to stop all possible miners..
for c in config['coins']:
control_miner(c,'command_stop')
#then we start the new miner if we have a profitable currency
if sortbuffer_val > 0:
escalate('mining: switched from %s to %s at aprox. $%0.2f'%(current_state,sortbuffer_key,sortbuffer_val));
control_miner(sortbuffer_key,'command_start')
current_state = sortbuffer_key
else:
escalate('not mining: no profitable currency found');
current_state = 'nothing'
s = open(config['statefilename'], 'w+')
s.write(current_state)
s.close()
f.close()