Example #1
0
 def __init__(self, filename, default=None, init=True, postfix=None):
     """ Persist constructor """
     if default and not type(default) == dict: raise DictNeeded(filename)
     filename = normdir(filename)
     self.origname = filename
     if postfix: self.fn = str(filename.strip()) + str("-%s" % postfix)
     else: self.fn = str(filename.strip())
     self.default = default
     self.data = None
     self.logname = reversename(stripdatadir(self.origname))
     self.ssize = 0
     self.input = ""
     self.dontsave = False
     if init: self.init()
Example #2
0
def markovlearnlog(chan):
    """ learn a log """
    lines = 0
    logfiles = os.listdir(getdatadir() + os.sep + "chatlogs")
    for filename in logfiles:
        if chan[1:] not in filename:
            continue
        logging.warn("opening %s" % reversename(filename))
        for line in open(getdatadir() + os.sep + "chatlogs" + os.sep + filename, "r"):
            if lines % 10 == 0:
                time.sleep(0.001)
            if not line:
                continue
            lines += 1
            try:
                txt = " ".join(
                    line.strip().split()[2:]
                )  # log format is: 2011-08-07 00:02:16  <botfather> love, peace and happiness
                markovtalk_learn(txt)
            except IndexError:
                continue
    logging.warn("learning %s log done. %s lines" % (chan, lines))
    return lines