-
Notifications
You must be signed in to change notification settings - Fork 2
/
halert.py
222 lines (197 loc) · 11 KB
/
halert.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/usr/bin/env python3
import requests,sys,json,time
import pygame
from datetime import datetime
import os
import platform
WD = [] #Full workers list
GW = []
BA = [] #Audio alert list
MH = [] #list of dict containing workername and minimum hashrate
def main():
try:
pygame.init() #Fast and dirty way to get true cross-platform audio play.
sysos = platform.system() #Get current OS (Linux,MAC,Windows)
if sysos == "Windows":
os.system('cls')
cwd = os.path.dirname(os.path.realpath(__file__))#Get current working dir
audio_file = cwd + '\\audio.wav' #Path to audio file
Sound = pygame.mixer.Sound(audio_file) #Define a Sound object with previous audio file
print("#####################################################################")
print("################# HeroMiners Crypto Worker Alerter###################")
print("#####################################################################")
print()
CRYPTO = input("Please enter the full name of your CRYPTO. (e.g: aeon,haven,monero): ") #This is used to point to correct subdomain
URL = "https://" + CRYPTO + ".herominers.com/api/stats_address?address=" #Start building URL
ADDRESS = input("Please enter your crypto address:")
URL = URL + ADDRESS + "&longpoll=false" #Finish building URL
intervalx = int(input("Please enter how many seconds do you want between each scans? (Recommended is 60 (1minute) or 600 (10minutes)): "))
if(intervalx <= 10):#10seconds is pretty quick already, no need to go crazy
intervalx = 10
brange = int(input("How many times should the alert ring?:"))
r = requests.get(url = URL)#GET request to HeroMiners API
data = r.json()
data = data['workers'] #Parsing, yay
for hr in data:
if(WD.count(hr['name']) <= 0): #Check if WD contains name of worker
WD.append(hr['name'])
x = "Yes"
try:
x = input("Do you want to add " + hr['name'] + " on the alert list ? Y or N(default is Y): ")
except:
print()
try:
if(x[0].upper() == "Y"):
BA.append(hr['name'])
except:
BA.append(hr['name'])
print("Current hashrate of " + str(hr['name']) + " is "+ str(hr['hashrate']))
y = 1
try:
y = int(input("Do you want to put a minimum hashrate for this worker? (Enter a number, 1 is default): "))
except:
print()
MH.append({"workername":str(hr['name']),"minhashrate":y})
while 1:
time.sleep(intervalx)
r = requests.get(url = URL)#get request to api
data = r.json() #serialize
data = data['workers'] #parse
print()
print()
print()
print()
print()
print()
print()
print()
now = datetime.now() #get time
now = now.strftime("%H:%M:%S") #print time
print("Time of scan: " + now)
print("##################################################")
for hr in data:
if(WD.count(hr['name']) <= 0): #check if new worker has been added
WD.append(hr['name'])
x = input("Do you want to add " + hr['name'] + " on the alert list ? Y or N: ")
if(x[0].upper() == "Y"):
BA.append(hr['name'])
print("Current hashrate of " + str(hr['name']) + " is "+ str(hr['hashrate']))
y = int(input("Do you want to put a minimum hashrate for this worker? (Enter a number, 0 is default): "))
if(y >= 1):
MH.append({"workername":str(hr['name']),"minhashrate":y})
#if(hr['hashrate'] == 0): #if worker hashrate is 0
# print(hr['name'] + " IS DOWN!!! ALERT ALERT ALERT ! ! !")
# if(BA.count(hr['name']) >= 1): #if it is on the audio alert list
# for i in range(brange): #iterate for the number of times desired
#print('\a')
#print(hr['name'] + " IS DOWN!!! ALERT ALERT ALERT ! ! !")
#Sound.play()
#TODO minimum hashrate
#if(hr['hashrate'] >= 1):
# print(hr['name'] + " IS OK.")
# if(GW.count(hr['name']) <= 1):
# GW.append(hr['name'])
#
for workerdata in MH:
if(workerdata['workername'] == hr['name']):
if(workerdata['minhashrate'] >= hr['hashrate']):
print(hr['name'] + " IS DOWN!!! ALERT ALERT ALERT ! ! !")
for workers in BA:
if(workers == hr['name']):
for i in range(brange):
Sound.play()
time.sleep(2)
if(workerdata['minhashrate'] < hr['hashrate']):
print(hr['name'] + " is OK.")
print("##################################################")
print()
#print(WD)
if sysos == "Linux":
os.system('clear')
cwd = os.path.dirname(os.path.realpath(__file__))
audio_file = cwd + '/audio.wav'
Sound = pygame.mixer.Sound(audio_file)
print("#####################################################################")
print("################# HeroMiners Crypto Worker Alerter###################")
print("#####################################################################")
print()
CRYPTO = input("Please enter the full name of your CRYPTO. (e.g: aeon,haven,monero): ")
URL = "https://" + CRYPTO + ".herominers.com/api/stats_address?address="
ADDRESS = input("Please enter your crypto address:")
URL = URL + ADDRESS + "&longpoll=false"
intervalx = int(input("Please enter how many seconds do you want between each scans? (Recommended is 60 (1minute) or 600 (10minutes)): "))
if(intervalx <= 10):
intervalx = 10
brange = int(input("How many times should the alert ring?:"))
r = requests.get(url = URL)
data = r.json()
data = data['workers']
if(WD.count(hr['name']) <= 0): #check if new worker has been added
WD.append(hr['name'])
try:
x = input("Do you want to add " + hr['name'] + " on the alert list ? Y or N(default is Y): ")
if(x[0].upper() == "Y"):
BA.append(hr['name'])
except:
BA.append(hr['name'])
print("Current hashrate of " + str(hr['name']) + " is "+ str(hr['hashrate']))
y = int(input("Do you want to put a minimum hashrate for this worker? (Enter a number, 0 is default): "))
if(y >= 1):
MH.append({"workername":str(hr['name']),"minhashrate":y})
while 1:
time.sleep(intervalx)
r = requests.get(url = URL)
data = r.json()
data = data['workers']
print()
print()
print()
print()
print()
print()
print()
print()
now = datetime.now()
now = now.strftime("%H:%M:%S")
print("Time of scan: " + now)
print("##################################################")
for hr in data:
if(WD.count(hr['name']) <= 0):
WD.append(hr['name'])
try:
x = input("Do you want to add " + hr['name'] + " on the alert list ? Y or N(default is Y): ")
if(x[0].upper() == "Y"):
BA.append(hr['name'])
except:
BA.append(hr['name'])
#if(hr['hashrate'] == 0):
# print(hr['name'] + " IS DOWN!!! ALERT ALERT ALERT ! ! !")
# if(BA.count(hr['name']) >= 1):
# for i in range(brange):
# #print('\a')
# #print(hr['name'] + " IS DOWN!!! ALERT ALERT ALERT ! ! !")
# Sound.play()
# #playsound(audio_file)
#
#if(hr['hashrate'] >= 1):
# print(hr['name'] + " IS OK.")
# if(GW.count(hr['name']) <= 1):
# GW.append(hr['name'])
#
for workerdata in MH:
if(workerdata['workername'] == hr['name']):
if(workerdata['minhashrate'] >= hr['hashrate']):
print(hr['name'] + " IS DOWN!!! ALERT ALERT ALERT ! ! !")
for workers in BA:
if(workers == hr['name']):
for i in range(brange):
Sound.play()
time.sleep(2)
if(workerdata['minhashrate'] < hr['hashrate']):
print(hr['name'] + " is OK.")
print("##################################################")
print()
#print(WD)
except Exception as e: print(e)
if __name__ == "__main__":
main()