<commit_before>#!/usr/bin/python

network = "irc.synirc.net"
nick = "skybot"
channel = "#cobol"

import sys
import os
import glob
import re
import thread
import Queue
import collections

sys.path += ['plugins'] # so 'import hook' works without duplication

import irc
import yaml

os.chdir(sys.path[0])   # do stuff relative to the installation directory


class Bot(object):

    def __init__(self, nick, channel, network):
        self.nick = nick
        self.channel = channel
        self.network = network

bot = Bot(nick, channel, network)

print 'Loading plugins'

plugin_mtimes = {}


def reload_plugins():

    if not hasattr(bot, 'plugs'):
        bot.plugs = collections.defaultdict(lambda: [])

    for filename in glob.glob("core/*.py") + glob.glob("plugins/*.py"):
        mtime = os.stat(filename).st_mtime
        if mtime != plugin_mtimes.get(filename):
            try:
                code = compile(open(filename, 'U').read(), filename, 'exec')
                locals = {}
                eval(code, locals)
            except Exception, e:
                print '    error:', e
                continue

            # remove plugins already loaded from this filename
            for name, data in bot.plugs.iteritems():
                bot.plugs[name] = filter(lambda x: x[0][0] != filename, data)

            for obj in locals.itervalues():
                if hasattr(obj, '_skybot_hook'): #check for magic
                    for type, data in obj._skybot_hook:
                        bot.plugs[type] += [data]
<commit_msg>don't shadow locals() with a variable<commit_after>#!/usr/bin/python

network = "irc.synirc.net"
nick = "skybot"
channel = "#cobol"

import sys
import os
import glob
import re
import thread
import Queue
import collections

sys.path += ['plugins'] # so 'import hook' works without duplication

import irc
import yaml

os.chdir(sys.path[0])   # do stuff relative to the installation directory


class Bot(object):

    def __init__(self, nick, channel, network):
        self.nick = nick
        self.channel = channel
        self.network = network

bot = Bot(nick, channel, network)

print 'Loading plugins'

plugin_mtimes = {}


def reload_plugins():

    if not hasattr(bot, 'plugs'):
        bot.plugs = collections.defaultdict(lambda: [])

    for filename in glob.glob("core/*.py") + glob.glob("plugins/*.py"):
        mtime = os.stat(filename).st_mtime
        if mtime != plugin_mtimes.get(filename):
            try:
                code = compile(open(filename, 'U').read(), filename, 'exec')
                namespace = {}
                eval(code, namespace)
            except Exception, e:
                print '    error:', e
                continue

            # remove plugins already loaded from this filename
            for name, data in bot.plugs.iteritems():
                bot.plugs[name] = filter(lambda x: x[0][0] != filename, data)

            for obj in namespace.itervalues():
                if hasattr(obj, '_skybot_hook'): #check for magic
                    for type, data in obj._skybot_hook:
                        bot.plugs[type] += [data]

{'fraction_non_alphanumeric': 0.1146598530820824, 'fraction_numerical': 0.0019163206643244969, 'mean_word_length': 2.2222222222222223, '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': '3323258', 'n_tokens_mistral': 927, 'n_tokens_neox': 884, 'n_words': 267}