Advertisement
Guest User

Untitled

a guest
Jun 27th, 2018
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. import websocket
  2. import json
  3.  
  4. def on_message(ws, message):
  5.     jsons = json.loads(message)
  6.     data_result = jsons.get('result')
  7.     if jsons.get('id') == 1:
  8.         height = int(data_result.get('previous')[0:8], 16)
  9.         ws.send(json.dumps({'id': 2, 'method': 'call', 'jsonrpc':'2.0', 'params': ['operation_history', 'get_ops_in_block', [height, 'false']]}))
  10.     elif jsons.get('id') == 2:
  11.         print(data_result)
  12.  
  13.  
  14. def on_error(ws, error):
  15.     print(error)
  16.  
  17. def on_close(ws):
  18.     print("### closed ###")
  19.  
  20. def on_open(ws):
  21.     ws.send(json.dumps({'id': 1, 'method': 'call', 'jsonrpc':'2.0', 'params': ['database_api', 'set_block_applied_callback', [0]]}))
  22.  
  23.  
  24. if __name__ == '__main__':
  25.     ws = websocket.WebSocketApp("wss://ws18.golos.io/",
  26.                                 on_message = on_message,
  27.                                 on_error = on_error,
  28.                                 on_close = on_close)
  29.     ws.on_open = on_open
  30.     ws.run_forever()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement