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

import os
import Queue
import sys
import traceback
import time

sys.path += ['plugins']  # so 'import hook' works without duplication
sys.path += ['lib']
os.chdir(sys.path[0] or '.')  # do stuff relative to the install directory


class Bot(object):
    def __init__(self):
        self.conns = {}
        self.persist_dir = os.path.abspath('persist')
        if not os.path.exists(self.persist_dir):
            os.mkdir(self.persist_dir)

bot = Bot()

print 'Loading plugins'

# bootstrap the reloader
eval(compile(open(os.path.join('core', 'reload.py'), 'U').read(),
             os.path.join('core', 'reload.py'), 'exec'))
reload(init=True)

print 'Connecting to IRC'

try:
    config()
    if not hasattr(bot, 'config'):
        exit()
except Exception, e:
    print 'ERROR: malformed config file:', e
    traceback.print_exc()
    sys.exit()

print 'Running main loop'

while True:
    reload()  # these functions only do things
    config()  # if changes have occured

    for conn in bot.conns.itervalues():
        try:
            out = conn.out.get_nowait()
            main(conn, out)
        except Queue.Empty:
            pass
    while all(conn.out.empty() for conn in bot.conns.itervalues()):
        time.sleep(.1)<commit_msg>wrap bot.py in a main() function to be import-safe<commit_after>#!/usr/bin/env python

import os
import Queue
import sys
import traceback
import time


class Bot(object):
    def __init__(self):
        self.conns = {}
        self.persist_dir = os.path.abspath('persist')
        if not os.path.exists(self.persist_dir):
            os.mkdir(self.persist_dir)

def main():
    sys.path += ['plugins']  # so 'import hook' works without duplication
    sys.path += ['lib']
    os.chdir(sys.path[0] or '.')  # do stuff relative to the install directory

    bot = Bot()

    print 'Loading plugins'

    # bootstrap the reloader
    eval(compile(open(os.path.join('core', 'reload.py'), 'U').read(),
                 os.path.join('core', 'reload.py'), 'exec'))
    reload(init=True)

    print 'Connecting to IRC'

    try:
        config()
        if not hasattr(bot, 'config'):
            exit()
    except Exception, e:
        print 'ERROR: malformed config file:', e
        traceback.print_exc()
        sys.exit()

    print 'Running main loop'

    while True:
        reload()  # these functions only do things
        config()  # if changes have occured

        for conn in bot.conns.itervalues():
            try:
                out = conn.out.get_nowait()
                main(conn, out)
            except Queue.Empty:
                pass
        while all(conn.out.empty() for conn in bot.conns.itervalues()):
            time.sleep(.1)

if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.1305916305916306, 'fraction_numerical': 0.001443001443001443, 'mean_word_length': 2.394124847001224, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6446706', 'n_tokens_mistral': 897, 'n_tokens_neox': 868, 'n_words': 243}