Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import queue
- import requests
- import websocket
- MESSAGE_TYPES = ['historyUpdate', 'queueUpdate', 'coinPriceUpdate', 'todayPricesUpdate', 'leaderboardUpdate', 'transactionUpate']
- # The keys might be useless, who knows?
- POLLING_URL_1 = 'https://nasfaq.biz/socket/?EIO=4&transport=polling&t=NZut4xm'
- POLLING_URL_2 = 'https://nasfaq.biz/socket/?EIO=4&transport=polling&t=NZv9M5m&sid={}'
- POLLING_URL_3 = 'https://nasfaq.biz/socket/?EIO=4&transport=polling&t=NZv9M5t&sid={}'
- COOKIE = {'holosesh': 'cockona'}
- HEADER = {
- 'Accept': '*/*',
- 'Accept-Encoding': 'gzip, deflate, br',
- 'Accept-Language': 'en-US,en;q=0.9',
- 'Connection': 'keep-alive',
- 'Cookie': 'holosesh=rrrrrat',
- 'Host': 'nasfaq.biz',
- 'Referer': 'https://nasfaq.biz/market',
- 'Sec-Fetch-Dest': 'empty',
- 'Sec-Fetch-Mode': 'cors',
- 'Sec-Fetch-Site': 'same-origin',
- 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36'
- }
- WSS_URL = 'wss://nasfaq.biz/socket/?EIO=4&transport=websocket&sid={}'
- class Socket_:
- def __init__(self, queue = None):
- self.URL = None
- self.sid = None
- self.parser = Parser().parser
- self.queue = queue
- self.ws = None
- # Start the connection
- self.handshake()
- def handshake(self):
- # Establish a polling-transport HTTP connection
- resp_1 = requests.get(POLLING_URL_1, headers = HEADER)
- # Ignore the bin-packed preliminaries and extract the session ID
- self.sid = json.loads(str(resp_1.content)[3:-1])['sid']
- # Second polling with POST, response should be 'ok'
- resp_2 = requests.post(POLLING_URL_2.format(self.sid), headers = HEADER, data = b'40')
- # Third polling, this one gives an unnecessary sid but the pipe breaks without this request.
- resp_3 = requests.get(POLLING_URL_3.format(self.sid), cookies = COOKIE, headers = HEADER)
- # WSS url
- self.URL = WSS_URL.format(self.sid)
- def on_open(self, ws):
- print('### Socket open ###')
- ws.send("2probe")
- def on_close(self, ws):
- print("### Socket closed ###")
- def on_error(self, ws, error):
- print('\nSocket error :\n{}\n'.format(error))
- def on_message(self, ws, message):
- if message == '2': ws.send('3')
- elif message == '3probe': ws.send('5')
- elif message[:2] == '42':
- # The message usually needs parsing
- #type_, res = self.parser(message)
- #self.queue.put( (type_, res) )
- def listenForever(self):
- try:
- #websocket.enableTrace(True)
- self.ws = websocket.WebSocketApp(self.URL,
- on_open = self.on_open,
- on_message = self.on_message,
- on_error = self.on_error,
- on_close = self.on_close,
- header = HEADER
- )
- self.ws.run_forever(ping_interval = 25, ping_timeout = 5 )
- except Exception as e:
- print("Socket::ListenForever: Exception {}", format(e))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement