-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpool_watcher.py
More file actions
103 lines (81 loc) · 2.71 KB
/
pool_watcher.py
File metadata and controls
103 lines (81 loc) · 2.71 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
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
from twilio.rest import Client
from datetime import datetime
from retrying import retry
from config import Config
from halo import Halo
import requests
import time
import os
# setup variables
config = Config().get()
account_sid = config.get('twilio', 'account_sid')
auth_token = config.get('twilio', 'auth_token')
client = Client(account_sid, auth_token)
done = False
def send_sms(body):
client.messages.create(
body=body,
from_=config.get('twilio', 'from'),
to=config.get('twilio', 'to')
)
def send_email(user, pwd, recipient, subject, body):
import smtplib
FROM = user
TO = recipient if isinstance(recipient, list) else [recipient]
SUBJECT = subject
TEXT = body
# Prepare actual message
message = """From: %s\nTo: %s\nSubject: %s\n\n%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
try:
server = smtplib.SMTP("smtp.gmail.com", 587)
server.ehlo()
server.starttls()
server.login(user, pwd)
server.sendmail(FROM, TO, message)
server.close()
print('successfully sent the mail')
except:
print("failed to send mail")
@retry
def get_hashrate():
response = requests.get(config.get('nanopool', 'url'))
hashrate = response.json()["data"]
return hashrate
def animate(current_hashrate):
with Halo(text=datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
' - hashing at ' + str(current_hashrate) + ' mh/s ', spinner='circle'):
time.sleep(300) # Wait 2 minute
def wait_drop():
# hashrate loop
current_hashrate = get_hashrate()
while current_hashrate != 0:
animate(current_hashrate)
current_hashrate = get_hashrate()
# if hashrate is 0 send sms and emal
send_sms('The rig stopped working!')
send_email(user=config.get('gmail', 'user'),
pwd=config.get('gmail', 'pwd'),
recipient=config.get('gmail', 'recipient'),
subject=config.get('gmail', 'subject'),
body='Current hashrate is 0 Mh/s... Operator has been notified.')
def wait_return():
# hashrate loop
current_hashrate = get_hashrate()
while current_hashrate == 0:
print('Waiting for mining to resume...')
current_hashrate = get_hashrate()
# if hashrate is 0 send sms and emal
send_sms('The rig is hashing again!')
send_email(user=config.get('gmail', 'user'),
pwd=config.get('gmail', 'pwd'),
recipient=config.get('gmail', 'recipient'),
subject=config.get('gmail', 'subject'),
body='The rig is working again!')
def main():
os.system('clear')
while 1:
wait_drop()
wait_return()
if __name__ == '__main__':
main()