<commit_before>import tornado.ioloop
from tornado.ioloop import IOLoop
import tornado.web
import tornado.websocket
import sys
import time
from networktables import NetworkTable
from tornado.websocket import WebSocketHandler
from tornado.options import define, options, parse_command_line
import logging
logging.basicConfig(level=logging.DEBUG)
define("port", default=8888, help="run on the given port", type=int)
'''
this should read and set values on a networktable when instructed,
'''
#link - http://localhost:8889/
#ip is probably 127.0.0.1
    
def valueChanged(table, key, value, isNew):
        IOLoop.current().add_callback(changeValue,key,value)
def changeValue(key,value):
        print(key,'has been changed to',value)
        #send a message to the website to change the value of the element
        #whose id=key to value
ipadd='127.0.0.1'
if len(ipadd) != 2:
    print("Error: specify an IP to connect to!")
NetworkTable.setIPAddress(ipadd)
NetworkTable.setClientMode()
NetworkTable.initialize()
sd = NetworkTable.getTable("SmartDashboard")
sd.addTableListener(valueChanged)
class EchoWebSocket(tornado.websocket.WebSocketHandler):
    print('echowebsocket created')
    
    def check_origin(self, origin):
        return True
    def open(self):
        print ("WebSocket opened")
    def writeStringToNetworkTable(self,message):
        '''
        message=key|message
        '''
        delimiterIndex=message.index('|')
        key=message[:delimiterIndex]
        newMessage=message[delimiterIndex+1:]
        print('key-',key,',message-',newMessage)
        sd.putString(key,newMessage)
    def on_message(self, message):
        prntout="You said:"+message
        print(prntout)
        #self.write_message(prntout,False)
        self.writeStringToNetworkTable(message)

    def on_close(self):
        print("WebSocket closed")

    #connectToIP(ipadd)

app = tornado.web.Application([
    (r'/', EchoWebSocket),
])
if __name__ == '__main__':
    print('starting')
    parse_command_line()
    app.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()
    print('goodbye')
#connectToIP(ipadd)
        
        <commit_msg>driverstationClientV1 updated, now baisically done<commit_after>import tornado.ioloop
from tornado.ioloop import IOLoop
import tornado.web
import tornado.websocket
import sys
import time
from networktables import NetworkTable
from tornado.websocket import WebSocketHandler
from tornado.options import define, options, parse_command_line
import logging
logging.basicConfig(level=logging.DEBUG)
define("port", default=8888, help="run on the given port", type=int)
'''
this should read and set values on a networktable when instructed,
'''
#link - http://localhost:8889/
#ip is probably 127.0.0.1
ipadd='127.0.0.1'
if len(ipadd) != 2:
        print("Error: specify an IP to connect to!")
NetworkTable.setIPAddress(ipadd)
NetworkTable.setClientMode()
NetworkTable.initialize()
sd = NetworkTable.getTable("SmartDashboard")
#sd.addTableListener(valueChanged)
class EchoWebSocket(tornado.websocket.WebSocketHandler):
    def __init__(self,application, request, **kwargs):
        sd.addTableListener(self.valueChanged)
        print('tableListenerhopefullyadded')
        super().__init__(application,request)
        
    print('echowebsocket created')
        
    def changeValue(self,key,value):
            print(key,'has been changed to',value)
            message=key+'|'+value
            self.write_message(message,False)
            #send a message to the website to change the value of the element
            #whose id=key to value
    def valueChanged(self,table, key, value, isNew):
            IOLoop.current().add_callback(self.changeValue,key,value)
            
    
    def check_origin(self, origin):
        return True
    def open(self):
        print ("WebSocket opened")
    def writeStringToNetworkTable(self,message):
        '''
        message=key|message
        '''
        delimiterIndex=message.index('|')
        key=message[:delimiterIndex]
        newMessage=message[delimiterIndex+1:]
        print('key-',key,',message-',newMessage)
        sd.putString(key,newMessage)
    def on_message(self, message):
        prntout="You said:"+message
        print(prntout)
        #self.write_message(prntout,False)
        self.writeStringToNetworkTable(message)

    def on_close(self):
        print("WebSocket closed")

    #connectToIP(ipadd)

app = tornado.web.Application([
    (r'/', EchoWebSocket),
])
if __name__ == '__main__':
    print('starting')
    parse_command_line()
    app.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()
    print('goodbye')
#connectToIP(ipadd)
        
        
{'fraction_non_alphanumeric': 0.11217539378458918, 'fraction_numerical': 0.009578544061302681, 'mean_word_length': 3.6756218905472635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '4116763', 'n_tokens_mistral': 1444, 'n_tokens_neox': 1381, 'n_words': 313}