Last PR modules: made some stabilization modifications

This commit is contained in:
nemunaire 2014-07-25 12:53:07 +02:00
parent d575c0d6d3
commit 9b010544b5
3 changed files with 62 additions and 95 deletions

View file

@ -20,23 +20,20 @@ def load(context):
def cmd_tcode(msg):
if (len(msg.cmds) < 2):
return Response(msg.sender,
"Demande incorrecte.\n %s" % help_full(),
msg.channel)
if len(msg.cmds) != 2:
raise IRCException("indicate a transaction code or a keyword to search!")
res = Response(msg.sender, None, msg.channel)
request = urllib.parse.quote(msg.cmds[1])
url = "http://www.tcodesearch.com/tcodes/search?q=" + request
url = "http://www.tcodesearch.com/tcodes/search?q=%s" % urllib.parse.quote(msg.cmds[1])
page = web.getURLContent(url)
res = Response(msg.sender, channel=msg.channel,
nomore="No more transaction code", count=" (%d more tcodes)")
if page is not None:
index = page.index('<div id="searchresults">') + len('<div id="searchresults">')
end = page[index:].index('</div>')+index
strscope = page[index:end]
for tcode in re.finditer('<strong> ([a-zA-Z0-9_]*)</strong> - ([^\n]*)\n', strscope):
res.append_message("\x02" + tcode.group(1)+"\x0F - "+striphtml(tcode.group(2)))
return res
else:
return None
res.append_message("\x02%s\x0F - %s" % (tcode.group(1), striphtml(tcode.group(2))))
return res