<commit_before>#!/usr/bin/env python

"""
Dash-2T
----

Dash second tier websockets and zeromq server

"""



import subprocess
import json
from websocket_server import WebsocketServer

dashd_path = "/Users/evan/Desktop/dash/src/dashd"
datadir = "/Users/evan/Desktop/.dash"

# Called for every client connecting (after handshake)
def new_client(client, server):
    print("New client connected and was given id %d" % client['id'])
    server.send_message_to_all("Hey all, a new client has joined us")


# Called for every client disconnecting
def client_left(client, server):
    print "disconnecting", client
    #print("Client(%d) disconnected" % client['id'])


# Called when a client sends a message
def message_received(client, server, message):
    if len(message) > 200:
        message = message[:200]+'..'
    print("Client(%d) said: %s" % (client['id'], message))

    #subprocess.call([dashd_path, datadir, json.dumps(client)])


PORT=5000
server = WebsocketServer(PORT)
server.set_fn_new_client(new_client)
server.set_fn_client_left(client_left)
server.set_fn_message_received(message_received)
server.run_forever()<commit_msg>draft<commit_after>#!/usr/bin/env python

"""
Dash-2T
----

Dash second tier websockets and zeromq server

"""



import subprocess
import json
from websocket_server import WebsocketServer

dashd_path = "/Users/evan/Desktop/dash/src/dash-cli"
datadir = "/Users/evan/.dash2"

# Called for every client connecting (after handshake)
def new_client(client, server):
    print("New client connected and was given id %d" % client['id'])
    server.send_message_to_all("Hey all, a new client has joined us")


# Called for every client disconnecting
def client_left(client, server):
    print "disconnecting", client
    #print("Client(%d) disconnected" % client['id'])


# Called when a client sends a message
def message_received(client, server, message):
    if len(message) > 200:
        message = message[:200]+'..'
    print("Client(%d) said: %s" % (client['id'], message))

    if(message.find("dapi_result") > 0):
        print("Request broadcast %d" % client['id'])
        server.send_message_to_all(message)
    else:
        print dashd_path, datadir
        f = open("/Users/evan/Desktop/tmp", "wb")
        f.write(message)
        f.close()
        subprocess.call(dashd_path + " --datadir=" + datadir + " dapif /Users/evan/Desktop/tmp", shell=True)


PORT=5000
server = WebsocketServer(PORT)
server.set_fn_new_client(new_client)
server.set_fn_client_left(client_left)
server.set_fn_message_received(message_received)
server.run_forever()
{'fraction_non_alphanumeric': 0.12993039443155452, 'fraction_numerical': 0.009280742459396751, 'mean_word_length': 4.469344608879493, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1620013', 'n_tokens_mistral': 890, 'n_tokens_neox': 837, 'n_words': 206}