Advertisement
Guest User

Untitled

a guest
May 29th, 2021
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. import json
  2. import queue
  3. import requests
  4. import websocket
  5.  
  6. MESSAGE_TYPES = ['historyUpdate', 'queueUpdate', 'coinPriceUpdate', 'todayPricesUpdate', 'leaderboardUpdate', 'transactionUpate']
  7. # The keys might be useless, who knows?
  8. POLLING_URL_1 = 'https://nasfaq.biz/socket/?EIO=4&transport=polling&t=NZut4xm'
  9. POLLING_URL_2 = 'https://nasfaq.biz/socket/?EIO=4&transport=polling&t=NZv9M5m&sid={}'
  10. POLLING_URL_3 = 'https://nasfaq.biz/socket/?EIO=4&transport=polling&t=NZv9M5t&sid={}'
  11. COOKIE = {'holosesh': 'cockona'}
  12. HEADER = {
  13. 'Accept': '*/*',
  14. 'Accept-Encoding': 'gzip, deflate, br',
  15. 'Accept-Language': 'en-US,en;q=0.9',
  16. 'Connection': 'keep-alive',
  17. 'Cookie': 'holosesh=rrrrrat',
  18. 'Host': 'nasfaq.biz',
  19. 'Referer': 'https://nasfaq.biz/market',
  20. 'Sec-Fetch-Dest': 'empty',
  21. 'Sec-Fetch-Mode': 'cors',
  22. 'Sec-Fetch-Site': 'same-origin',
  23. 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36'
  24. }
  25. WSS_URL = 'wss://nasfaq.biz/socket/?EIO=4&transport=websocket&sid={}'
  26.  
  27. class Socket_:
  28. def __init__(self, queue = None):
  29. self.URL = None
  30. self.sid = None
  31. self.parser = Parser().parser
  32. self.queue = queue
  33. self.ws = None
  34.  
  35. # Start the connection
  36. self.handshake()
  37.  
  38. def handshake(self):
  39. # Establish a polling-transport HTTP connection
  40. resp_1 = requests.get(POLLING_URL_1, headers = HEADER)
  41. # Ignore the bin-packed preliminaries and extract the session ID
  42. self.sid = json.loads(str(resp_1.content)[3:-1])['sid']
  43. # Second polling with POST, response should be 'ok'
  44. resp_2 = requests.post(POLLING_URL_2.format(self.sid), headers = HEADER, data = b'40')
  45. # Third polling, this one gives an unnecessary sid but the pipe breaks without this request.
  46. resp_3 = requests.get(POLLING_URL_3.format(self.sid), cookies = COOKIE, headers = HEADER)
  47. # WSS url
  48. self.URL = WSS_URL.format(self.sid)
  49.  
  50. def on_open(self, ws):
  51. print('### Socket open ###')
  52. ws.send("2probe")
  53. def on_close(self, ws):
  54. print("### Socket closed ###")
  55. def on_error(self, ws, error):
  56. print('\nSocket error :\n{}\n'.format(error))
  57.  
  58. def on_message(self, ws, message):
  59. if message == '2': ws.send('3')
  60. elif message == '3probe': ws.send('5')
  61. elif message[:2] == '42':
  62. # The message usually needs parsing
  63. #type_, res = self.parser(message)
  64. #self.queue.put( (type_, res) )
  65.  
  66. def listenForever(self):
  67. try:
  68. #websocket.enableTrace(True)
  69. self.ws = websocket.WebSocketApp(self.URL,
  70. on_open = self.on_open,
  71. on_message = self.on_message,
  72. on_error = self.on_error,
  73. on_close = self.on_close,
  74. header = HEADER
  75. )
  76. self.ws.run_forever(ping_interval = 25, ping_timeout = 5 )
  77. except Exception as e:
  78. print("Socket::ListenForever: Exception {}", format(e))
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement