-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
67 lines (45 loc) · 1.81 KB
/
app.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
from flask import Flask, render_template, request
from flask_socketio import SocketIO
from datetime import datetime
app = Flask(__name__)
app.config['SECRET_KEY'] = 'reddoshi!'
socketio = SocketIO(app, cors_allowed_origins='*')
"""
Get current date time
"""
def get_current_datetime():
now = datetime.now()
return now.strftime("%m/%d/%Y %H:%M:%S")
@app.route('/')
def index(): # site root
return render_template('index.html')
@app.route('/stakenotify/<txid>/<blockhash>/<int:height>/<walletname>')
def stakenotify(txid="", blockhash="", height=-1, walletname=""): # receive stake notify
socketio.emit('updateStake', {'date': get_current_datetime(), 'wallet': str(walletname), 'txid': str(txid), 'blockhash': str(blockhash), 'height': height})
return str(txid)
@app.route('/walletnotify/<txid>/<blockhash>/<int:height>/<walletname>')
def walletnotify(txid="", blockhash="", height=-1, walletname=""): # receive walletnotify notify
socketio.emit('updateWallet', {'date': get_current_datetime(), 'wallet': str(walletname), 'txid': str(txid), 'blockhash': str(blockhash), 'height': height})
return str(txid)
@app.route('/alertnotify/<alertmsg>')
def alertnotify(alertmsg=""): # receive alert notify
socketio.emit('updateAlert', {'date': get_current_datetime(), 'alertmsg': str(alertmsg)})
return str(alertmsg)
@app.route('/blocknotify/<blockhash>')
def blocknotify(blockhash=""): # receive block notify
socketio.emit('updateBlock', {'date': get_current_datetime(), 'blockhash': str(blockhash)})
return str(blockhash)
"""
Decorator for connect
"""
@socketio.on('connect')
def connect():
print('Client connected')
"""
Decorator for disconnect
"""
@socketio.on('disconnect')
def disconnect():
print('Client disconnected', request.sid)
if __name__ == '__main__':
socketio.run(app)