-
Notifications
You must be signed in to change notification settings - Fork 9
/
mreq.py
109 lines (90 loc) · 2.2 KB
/
mreq.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
#
# (c) 2017 elias/vanissoft
#
#
#
#
import datetime
import json
import redis
import pickle
from config import Redisdb, Bitshares
def launch(data):
"""
Signals start distribution
:param data:
:return:
"""
Redisdb.rpush("messages", "---------------")
Redisdb.rpush("messages", datetime.datetime.now().isoformat()+" Distribution Starts")
data['operation'] = 'launch_distribution'
Redisdb.rpush("operations", pickle.dumps(data))
def snapshot(data):
"""
Signals the start of snapshot
:param data:
:return:
"""
Redisdb.rpush("messages", "---------------")
msg = datetime.datetime.now().isoformat()+" Snapshot Starts"
Redisdb.rpush("messages", msg)
data['operation'] = 'launch_snapshot'
Redisdb.rpush("operations", pickle.dumps(data))
def get_account(acc):
rtn = Bitshares.rpc.get_account_by_name(acc)
if rtn is None:
return {'td_msg': '????', 'id': None}
else:
rtn['td_msg'] = 'id: '+rtn['id']
return rtn
def get_asset(ass):
rtn = Bitshares.rpc.lookup_asset_symbols([ass])
if rtn[0] is None:
return {'td_msg': '????', 'id': None}
else:
rtn[0]['td_msg'] = 'id: '+rtn[0]['id']
return rtn[0]
def getinfo(args, tag, path, query_string):
"""
http://127.0.0.1:8099/get/froga?sadf=324&asd=34
args = {'asd': ['34'], 'sadf': ['324']} froga
:param req:
:param tag:
:return:
"""
rtn = {'data': None}
#print("getinfo:", args, tag, path, query_string)
if tag == 'getaccount':
if 'account' in args:
rtn['data'] = get_account(args['account'][0])
elif tag == 'getasset':
if 'asset' in args:
rtn['data'] = get_asset(args['asset'][0])
elif tag == 'getmessage':
msg_arr = []
while True:
msg = Redisdb.lpop("messages")
if msg is None:
break
msg_arr.append(msg.decode('utf8'))
if len(msg_arr) > 100:
break
if len(msg_arr) > 0:
rtn['data'] = msg_arr
rtn['request'] = path+"?"+query_string
return rtn
def postinfo(args, tag, path, query_string, djson):
"""
"""
rtn = {}
print("postinfo:", args, tag, path, query_string, djson)
if tag == 'launch':
launch(djson)
rtn['data'] = "started"
elif tag == 'snapshot':
snapshot(djson)
rtn['data'] = "started"
rtn['request'] = path + "?" + query_string
return json.dumps(rtn)
if __name__ == '__main__':
print(0)