<commit_before>import serial
import time
import threading
from socketIO_client import SocketIO, LoggingNamespace, BaseNamespace
from threading import Thread
from tendo import singleton
import configparser

me = singleton.SingleInstance()

config = configparser.ConfigParser()
config.read('./config.cfg')

password = config.get('variables', 'password')

media_hub_url = 'http://dev-uos-mediahub.azurewebsites.net'

score = {
        "play": {
            "themes": [
            ],
            "scenes": [
                "586f853ab8678acc10b1595d"
            ]
        }
    }


class PublishMediaFrameworkMessages:
    def on_auth_r(self, *args):
        print('on_auth_r', args)

    def __init__(self):
        self.socketio = SocketIO(media_hub_url, 80, LoggingNamespace)
        self.socketio.emit('auth', {'password': password}, self.on_auth_r)
        self.socketio.wait_for_callbacks(seconds=10)

        self.receive_events_thread = Thread(target=self._receive_events_thread)
        self.receive_events_thread.daemon = True
        self.receive_events_thread.start()

        yes = False

        while True:
            reading = serial_port.readline()
            electret_peak_sample = reading
            handle_data(electret_peak_sample)
            self.publish(yes)
            yes = True

    def _receive_events_thread(self):
        self.socketio.wait()

    def publish(self, should_publish):
        print("publish")
        print(should_publish)
        if not should_publish:
            self.socketio.emit('sendCommand', 'electret', 'showScenesAndThemes', score)


# serial connection
port = '/dev/ttyACM0'
baud = 9600
serial_port = serial.Serial(port, baud)


def handle_data(data):
    try:
        print(data)
        electret_peak_sample = int(data)
        if electret_peak_sample < 50:
            print("very quiet")
        elif electret_peak_sample < 500:
            print("medium noise")
        else:
            print("noisy")
    except:
        print("Error")


def read_from_port(ser):
    # read serial port for data

    # ws_messenger = PublishMediaFrameworkMessages()

    while True:
        reading = ser.readline()
        electret_peak_sample = reading
        handle_data(electret_peak_sample)
        # ws_messenger.publish(should_publish)


def main():
    # thread = threading.Thread(target=read_from_port, args=(serial_port,))
    # thread.daemon = True
    # thread.start()

    ws_messenger = PublishMediaFrameworkMessages()

if __name__ == "__main__":
    main()<commit_msg>basic exit logic and we can remove after testing<commit_after>import serial
import time
import threading
from socketIO_client import SocketIO, LoggingNamespace, BaseNamespace
from threading import Thread
from tendo import singleton
import configparser
import sys

me = singleton.SingleInstance()

config = configparser.ConfigParser()
config.read('./config.cfg')

password = config.get('variables', 'password')

media_hub_url = 'http://dev-uos-mediahub.azurewebsites.net'

score = {
        "play": {
            "themes": [
            ],
            "scenes": [
                "586f853ab8678acc10b1595d"
            ]
        }
    }


class PublishMediaFrameworkMessages:
    def on_auth_r(self, *args):
        print('on_auth_r', args)

    def __init__(self):
        self.socketio = SocketIO(media_hub_url, 80, LoggingNamespace)
        self.socketio.emit('auth', {'password': password}, self.on_auth_r)
        self.socketio.wait_for_callbacks(seconds=10)

        self.receive_events_thread = Thread(target=self._receive_events_thread)
        self.receive_events_thread.daemon = True
        self.receive_events_thread.start()

        yes = False

        while True:
            reading = serial_port.readline()
            electret_peak_sample = reading
            handle_data(electret_peak_sample)
            self.publish(yes)
            yes = True

    def _receive_events_thread(self):
        self.socketio.wait()

    def publish(self, should_publish):
        print("publish")
        print(should_publish)
        if not should_publish:
            self.socketio.emit('sendCommand', 'electret', 'showScenesAndThemes', score)
        if should_publish:
            sys.exit('we have published')


# serial connection
port = '/dev/ttyACM0'
baud = 9600
serial_port = serial.Serial(port, baud)


def handle_data(data):
    try:
        print(data)
        electret_peak_sample = int(data)
        if electret_peak_sample < 50:
            print("very quiet")
        elif electret_peak_sample < 500:
            print("medium noise")
        else:
            print("noisy")
    except:
        print("Error")


def main():
    ws_messenger = PublishMediaFrameworkMessages()

if __name__ == "__main__":
    main()
{'fraction_non_alphanumeric': 0.09867730422002939, 'fraction_numerical': 0.012597102666386731, 'mean_word_length': 2.6617986164488854, 'pattern_counts': {'":': 8, '<': 7, '<?xml version=': 0, '>': 3, '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': '224633', 'n_tokens_mistral': 1495, 'n_tokens_neox': 1397, 'n_words': 285}