-
Notifications
You must be signed in to change notification settings - Fork 0
/
blocknotif.py
64 lines (52 loc) · 1.42 KB
/
blocknotif.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
import sys
import json
import requests
import re
import time
import os
class Account(object):
def __init__(self, name, address, soundPath):
self.name = name
self.address = address
self.soundPath = soundPath
self.numBlocks = 0
def update(self, isStartup=False):
newNumBlocks = self.getNumBlocks()
if self.numBlocks < newNumBlocks and not isStartup:
os.system('aplay ' + self.soundPath)
print self.name + ' found block!!! New balance: ' + str(newNumBlocks)
self.numBlocks = newNumBlocks
def getNumBlocks(self):
html = requests.get('http://etherchain.org/account/' + self.address).text
#Mined Blocks: 89
regx = re.compile('Mined Blocks: ([\d]*)')
res = regx.search(html)
if not res:
raise Exception('No number of mined blocks found!')
return res.group(1)
def getConfig():
if len(sys.argv) == 1:
print 'must specify a config as parameter, aborting...'
exit()
configUrl = sys.argv[1]
try:
with open(configUrl) as confFile:
try:
return json.loads(confFile.read())
except ValueError:
print 'config is not json, aborting...'
exit()
except IOError:
print 'blocknotif.conf not found, aborting...'
exit()
config = getConfig()
accts = []
for acct in config['accounts']:
print "Adding account for " + acct['name']
accts.append(Account(acct['name'], acct['address'], acct['wav']))
for acct in accts:
acct.update(True)
while True:
for acct in accts:
acct.update()
time.sleep(30)