<commit_before>#!/usr/local/bin/python3 -u
__author__    = '<NAME> <https://github.com/fxstein>'
__copyright__ = 'Copyright (C) 2015 <NAME>'
__license__   = 'Apache License, Version 2.0'

# Make sure we have access to SentientHome commons
import os, sys
sys.path.append(os.path.dirname(os.path.abspath(__file__))  + '/..')

# Sentient Home configuration
from common.shconfig import shConfig
from common.shutil import flatten_dict
from common.sheventhandler import shEventHandler

# Add path to submodule dependencies.ISYlib-python
sys.path.append(os.path.dirname(os.path.abspath(__file__))  + '/../dependencies/ISYlib-python')
from ISY.IsyEvent import ISYEvent

import logging as log

config = shConfig('~/.config/home/home.cfg', name='Universal Devices ISY994')
handler = shEventHandler(config)


# Realtime event feeder
def eventFeed(*arg):

    # Flatten dict and turned ebeded structure into dot notation
    data = flatten_dict(arg[0])

    event = [{
        'name': 'isy',
        'columns': list(data.keys()),
        'points': [ list(data.values()) ]
    }]

    log.debug('Event data: %s', event)

    handler.postEvent(event)

    # Reload config if modified - self limited to once every 10s+
    config.reloadModifiedConfig()

# Setup ISY socket listener
# Be aware: Even though we are able to update the config at runtime
# we do not take down the web socket subscription once established
server = ISYEvent()

retries = 0

while True:
    try:
        server.subscribe(addr=config.get('isy', 'isy_addr'),\
                         userl=config.get('isy', 'isy_user'),\
                         userp=config.get('isy', 'isy_pass'))
        break
    except Exception:
        retries += 1

        log.warn('Cannot connect to ISY. Attempt %n of %n',\
                        retries, config.retries)

        if retries >= config.retries:
            log.Error('Unable to connect to ISY. Exiting...')
            raise

        # Wait for the next poll intervall until we retry
        # also allows for configuration to get updated
        handler.sleep()
        continue


server.set_process_func(eventFeed, "")

try:
    print('Use Control-C to exit')
    server.events_loop()   #no return
except KeyboardInterrupt:
    log.info('Exiting...')
<commit_msg>Fix minor typo<commit_after>#!/usr/local/bin/python3 -u
__author__    = '<NAME> <https://github.com/fxstein>'
__copyright__ = 'Copyright (C) 2015 <NAME>'
__license__   = 'Apache License, Version 2.0'

# Make sure we have access to SentientHome commons
import os, sys
sys.path.append(os.path.dirname(os.path.abspath(__file__))  + '/..')

# Sentient Home configuration
from common.shconfig import shConfig
from common.shutil import flatten_dict
from common.sheventhandler import shEventHandler

# Add path to submodule dependencies.ISYlib-python
sys.path.append(os.path.dirname(os.path.abspath(__file__))  + '/../dependencies/ISYlib-python')
from ISY.IsyEvent import ISYEvent

import logging as log

config = shConfig('~/.config/home/home.cfg', name='Universal Devices ISY994')
handler = shEventHandler(config)


# Realtime event feeder
def eventFeed(*arg):

    # Flatten dict and turn embedded structure into dot notation
    data = flatten_dict(arg[0])

    event = [{
        'name': 'isy',
        'columns': list(data.keys()),
        'points': [ list(data.values()) ]
    }]

    log.debug('Event data: %s', event)

    handler.postEvent(event)

    # Reload config if modified - self limited to once every 10s+
    config.reloadModifiedConfig()

# Setup ISY socket listener
# Be aware: Even though we are able to update the config at runtime
# we do not take down the web socket subscription once established
server = ISYEvent()

retries = 0

while True:
    try:
        server.subscribe(addr=config.get('isy', 'isy_addr'),\
                         userl=config.get('isy', 'isy_user'),\
                         userp=config.get('isy', 'isy_pass'))
        break
    except Exception:
        retries += 1

        log.warn('Cannot connect to ISY. Attempt %n of %n',\
                        retries, config.retries)

        if retries >= config.retries:
            log.Error('Unable to connect to ISY. Exiting...')
            raise

        # Wait for the next poll intervall until we retry
        # also allows for configuration to get updated
        handler.sleep()
        continue


server.set_process_func(eventFeed, "")

try:
    print('Use Control-C to exit')
    server.events_loop()   #no return
except KeyboardInterrupt:
    log.info('Exiting...')

{'fraction_non_alphanumeric': 0.11490204710543693, 'fraction_numerical': 0.006603565925599824, 'mean_word_length': 2.920621225194133, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 2, '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': '2842839', 'n_tokens_mistral': 1398, 'n_tokens_neox': 1331, 'n_words': 400}