Add multi-line fectoids to webinterface, add @mcgyver for mcgyver facts

This commit is contained in:
Dennis Kaarsemaker 2006-07-17 11:05:42 +02:00
parent 1b1e1d1787
commit b6f6704b03
2 changed files with 46 additions and 5 deletions

View File

@ -22,7 +22,7 @@ def link(match):
return '<a href="%s">%s</a>' % (url, txt)
def q(txt):
txt = str(txt).replace('&','&amp;').replace('<','&lt;').replace('>','&gt;').replace('"','&quot;').replace('\n','<br />')
txt = str(txt).replace('&','&amp;').replace('<','&lt;').replace('>','&gt;').replace('"','&quot;').replace('\n','<br />').replace('$hr$','<hr />')
# linkify
rx = re.compile('(?P<url>(https?://\S+|www\S+))')
return rx.sub(link, txt)
@ -64,13 +64,17 @@ out(' <a href="factoids.cgi?db=%s&order=%s&page=%d">%s</a> &middot;' % (database
out('<table cellspacing="0"><tr><th>Factoid</th><th>Value</th><th>Author</th></tr>')
cur.execute("SELECT name, value, author, added, popularity FROM facts WHERE value NOT LIKE '<alias>%%' ORDER BY %s LIMIT %d, %d" % (order_by, page*NUM_PER_PAGE, NUM_PER_PAGE))
cur.execute("SELECT name, value, author, added, popularity FROM facts WHERE value NOT LIKE '<alias>%%' AND name NOT LIKE '%%-also' ORDER BY %s LIMIT %d, %d" % (order_by, page*NUM_PER_PAGE, NUM_PER_PAGE))
factoids = cur.fetchall()
i = 0
for f in factoids:
cur.execute("SELECT name FROM facts WHERE value LIKE %s", '<alias> ' + f[0])
f = list(f)
f[0] += '\n' + '\n'.join([x[0] for x in cur.fetchall()])
cur.execute("SELECT value FROM facts WHERE name = %s", f[0] + '-also')
more = cur.fetchall()
if len(more):
f[1] += ' $hr$' + ' $hr$'.join([x[0] for x in more])
cur.execute("SELECT name FROM facts WHERE value LIKE %s", '<alias> ' + f[0])
f[0] += ' \n' + ' \n'.join([x[0] for x in cur.fetchall()])
out('<tr')
if i % 2: out(' class="bg2"')
i += 1

View File

@ -24,7 +24,9 @@ class Mess(callbacks.PluginRegexp):
jre1 = ('http://www.jackbauerfacts.com/index.php?rate_twenty_four',
re.compile('current-rating.*?width.*?<td>(.*?)</td>', re.DOTALL))
jre2 = ('http://www.notrly.com/jackbauer/',
re.compile('<p class="fact">(.*?)</p>'))
re.compile('<p class="fact">(.*?)</p>', re.DOTALL))
mgurl = ('http://www.macgyver.co.za/',
re.compile(r'wishtable">(.*?)<div', re.DOTALL))
badwords = ['sex','masturbate','fuck','rape','dick','pussy','prostitute','hooker',
'orgasm','sperm','cunt','penis','shit','piss','urin','bitch','semen']
i = 0
@ -78,6 +80,7 @@ class Mess(callbacks.PluginRegexp):
val = self.entre.sub(entities[entity], val)
else:
val = self.entre.sub('?', val)
val = val.replace('<br />','').replace('\n','').replace('\r','')
_val = val.lower()
for word in self.badwords:
if word in _val:
@ -205,6 +208,15 @@ class Mess(callbacks.PluginRegexp):
irc.reply(f)
bauer = wrap(bauer)
def macgyver(self, irc, msg, args, count=0):
""" Display a macgyver fact """
if not self.ok(msg.args[0]): return
f = self._macgyver()
if f:
irc.reply(f)
macgyver = wrap(macgyver)
mcgyver = macgyver
def futurama(self, irc, msg, args):
""" Display a futurama quote """
if not self.ok(msg.args[0]): return
@ -257,5 +269,30 @@ class Mess(callbacks.PluginRegexp):
except:
time.sleep(1)
return self._bauer(count+1)
def _macgyver(self,count=0):
(url, rx) = self.mgurl
if count > 5:
return
try:
fact = utils.web.getUrl(url)
reo = rx.search(fact)
val = reo.group(1).replace('<p>','').replace('</p>','').replace('&quot;','"').replace('&nbsp;',' ')
val = re.sub(r'\s+', ' ', val).strip()
while self.entre.search(val):
entity = self.entre.search(val).group(1)
print entity
if entity in entities:
val = self.entre.sub(entities[entity], val)
else:
val = self.entre.sub('?', val)
_val = val.lower()
for word in self.badwords:
if word in _val:
raise RuntimeError
return val
except:
time.sleep(1)
return self._macgyver(count+1)
Class = Mess