<commit_before>import websocket
import requests

class Socket(websocket.WebSocketApp):
    def __init__(self, namespace=None):
        self.namespace = namespace 
        #port_number =  5000
        website_url = 'http://www.watchpeoplecode.com/socket.io/1/'
        r = requests.post(website_url)
        params = r.text
        key, heartbeat_timeout, connection_timeout, supported_transports = \
                params.split(':') 

        website_socket = website_url.replace('http', 'ws') + 'websocket/'
        super(Socket, self).__init__(website_socket + key)

    def on_open(self):
        print('Websocket open!')

    def on_close(self):
        print('Websocket closed!')

    def on_message(self, message):
        print(message)

    def on_error(self, e):
        print(e)

    def _namespace_helper(self, namespace=None):
        """
        This is a small helper to determine the namespace state.
        """
        if namespace is None and self.namespace is None:
            namespace = ''
        else namespace is None:
            namespace = self.namespace
        return namespace
    
    def disconnect(self, namespace=None):
        namespace = self._namespace_helper(namespace)
        # '0::namespace'
        self.send(':'.join(0, '', namespace, ''))

    def send_packet_helper(self, 
                           type_key, 
                           namespace=None, 
                           data=None, 
                           callback=None):

        if callback is not None:
            print('Callbacks not implemented in `send_packet_helper` in `Socket`')

        callback = ''
        namespace = self._namespace_helper(namespace)
        self.send(':'.join([type_key, callback, namespace, data]))

    # for reference!
    TYPE_KEYS = {'CONNECT':0, 
                 'DISCONNECT':1, 
                 'EVENT':2, 
                 'ACK':3, 
                 'ERROR':4,
                 'BINARY_EVENT':5,
                 'BINARY_ACK':6}

if __name__ == '__main__':
    streamer_name = 'beohoff'
    # this is default for the flask app
    socket = Socket()
    socket.run_forever()
<commit_msg>finally connected to the server!<commit_after>import websocket
import json
import requests


class Socket(websocket.WebSocketApp):
    def __init__(self, namespace='/chat'):
        self.namespace = namespace 
        #port_number =  5000
        website_url = 'http://www.watchpeoplecode.com/socket.io/1/'
        r = requests.post(website_url)
        params = r.text
        key, heartbeat_timeout, connection_timeout, supported_transports = \
                params.split(':') 

        website_socket = website_url.replace('http', 'ws') + 'websocket/'
        super(Socket, self).__init__(website_socket + key,
                                     on_open=self.on_open, on_close=self.on_close,
                                     on_message=self.on_message, 
                                     on_error=self.on_error)

        #self.send_packet_helper(0)
        #self.send_packet_helper(5, data="{'name':'initialize'}")

    def on_open(self, *args):
        print('Websocket open!')

    def on_close(self, *args):
        print('Websocket closed!')
    
    def on_message(self, *args):
        message = args[1].split(':')
        key = int(message[0])
        callback =message[1]
        namespace = message[2]

        if len(message) == 4:
           data = message[3]
        else:
            data = ''
        print('Key: ', key) 
        if key == 1 and args[1] == '1::':
            print("Connecting to namespace!")
            self.send_packet_helper(1)
        elif key == 1 and args[1] == '1::/chat':
            self.send_packet_helper(5, data={'name':'initialize'})
            self.send_packet_helper(5, data={'name':'join', 'args':['beohoff']})
        if key == 2:
            pass

        print(args[1])
        

    def on_error(self, *args):
        print(args)

    def disconnect(self):
        callback = ''
        data = ''
        # '1::namespace'
        self.send(':'.join([str(self.TYPE_KEYS['DISCONNECT']), 
                           callback, self.namespace, data]))
    """    
    def emit(self, type_key, data):
        data = json.dumps(data)
        self.send(':'
    """
    def send_packet_helper(self, 
                           type_key, 
                           data=None, 
                           callback=None):

        if callback is not None:
            print('Callbacks not implemented in `send_packet_helper` in `Socket`')
        if data is None:
            data = ''
        else:
            data = json.dumps(data)

        callback = ''
        message = ':'.join([str(type_key), callback, self.namespace, data])
        print("Packet helper: ", message)
        self.send(message)
    
    LISTNER_KEYS = {'DISCONNECT':0,
                    'CONNECT':1,
                    'HEARTBEAT':2,
                    'MESSAGE':3,
                    'JSON':4,
                    'EVENT':5,
                    'ACK':6,
                    'ERROR':7}

    # for reference!
    TYPE_KEYS = {'CONNECT':0, 
                 'DISCONNECT':1, 
                 'EVENT':2, 
                 'ACK':3, 
                 'ERROR':4,
                 'BINARY_EVENT':5,
                 'BINARY_ACK':6}

if __name__ == '__main__':
    streamer_name = 'beohoff'
    # this is default for the flask app
    socket = Socket()
    socket.run_forever()

{'fraction_non_alphanumeric': 0.1211453744493392, 'fraction_numerical': 0.009911894273127754, 'mean_word_length': 1.6961900049480456, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '223257', 'n_tokens_mistral': 1601, 'n_tokens_neox': 1528, 'n_words': 324}