def __init__(self, **kw): if 'pid' in kw and kw['pid']: self.pid = kw['pid'] else: self.pid = random.randint(1, 1607) self.tags = {} self.url = 'http://www.cs.rice.edu/~ssiyer/minstrels/txt/%s.txt' % \ self.pid log.critical(self.url) self.retries = 3
def ask(self, irc, msg): channel = msg.args[0] if channel not in self.curQuestion: self.curQuestion[channel] = self.getQuestion() irc.queueMsg(ircmsgs.privmsg(channel,u"%s: %s?" % (ircutils.bold(self.curQuestion[channel].id), self.curQuestion[channel].question))) irc.queueMsg(ircmsgs.privmsg(channel,ircutils.bold("Answer: ") + self.curQuestion[channel].hint)) # Print answer to log for debugging purposes only log.critical(self.curQuestion[channel].answer) return
def _importFiles(self, dirname, fnames, *args): for name in args[0]: path = os.path.join(self.imports, name) log.critical('II%s', path) f = open(path, 'r') tags = {} for l in f: l = l.strip() if l.startswith('#'): pass #comment elif l.startswith('@'): L = l.split(' ') name = L[0][1:] val = ' '.join(L[1:]) tags[name] = val else: tags.setdefault('body', []).append(l) log.critical('II%s', tags) self.add(**tags)
def _importFiles(self, dirname, fnames, *args): for name in args[0]: path = os.path.join(self.imports, name) log.critical('II%s' , path) f = open(path, 'r') tags = {} for l in f: l = l.strip() if l.startswith('#'): pass #comment elif l.startswith('@'): L = l.split(' ') name = L[0][1:] val = ' '.join(L[1:]) tags[name] = val else: tags.setdefault('body', []).append(l) log.critical('II%s' , tags) self.add(**tags)
def add(self, **kw): if 'body' in kw and 'author' in kw: kw['firstline'] = kw['body'][0] if not 'title' in kw: kw['title'] = '' if not 'id' in kw: kw['lastplayed'] = 1 kw['totalplayings'] = 0 kw['rating'] = 5.0 kw['comments'] = [] oldPoem = self.exists(**kw) if oldPoem: log.critical('old exists bailing') return oldPoem else: newPoem = PoemRecord(**kw) self.db.add(newPoem) return newPoem else: log.critical('%s' % kw)
def fetch(self): txt = utils.web.getUrl(self.url) if not 'was not found' in txt: L = txt.split('\n') L.pop() self.tags['title'] = L.pop(0).strip("'") self.tags['author'] = L.pop().split('--')[-1].strip() while L[0] == '': L.pop(0) while L[-1] == '': L.pop() self.tags['body'] = L self.tags['firstline'] = L[0] self.tags['wwwid'] = self.pid return self.tags else: log.critical('nomatch %s' % txt) if self.retries > 0: self.retries -= 1 self.fetch() else: return None
def setUp(self): log.critical('Beginning test case %s', self.id()) threads = [t.getName() for t in threading.enumerate()] log.critical('Threads: %L', threads) unittest.TestCase.setUp(self)
def _evaluatePoem(self, poem): since = time.time() - poem.lastplayed score = since / (poem.totalplayings + 0.1) log.critical('score %s', score) return score
def __call__(self, irc, msg, args, text): log.critical(text) irc.replySuccess()