2014-07-24 03:32:07 +00:00
|
|
|
# coding=utf-8
|
|
|
|
|
2014-08-27 23:39:31 +00:00
|
|
|
"""Find information about an SAP transaction codes"""
|
|
|
|
|
2014-07-24 03:32:07 +00:00
|
|
|
import urllib.request
|
|
|
|
import json
|
|
|
|
import re
|
2014-08-12 18:10:19 +00:00
|
|
|
|
|
|
|
from hooks import hook
|
2014-07-24 03:32:07 +00:00
|
|
|
from tools import web
|
|
|
|
from tools.web import striphtml
|
|
|
|
|
2014-08-13 13:53:55 +00:00
|
|
|
nemubotversion = 3.4
|
2014-07-24 03:32:07 +00:00
|
|
|
|
2014-09-26 16:00:22 +00:00
|
|
|
from more import Response
|
|
|
|
|
2014-07-24 03:32:07 +00:00
|
|
|
|
2014-11-13 01:51:49 +00:00
|
|
|
def help_full():
|
|
|
|
return "!tcode <transaction code|keywords>"
|
2014-07-24 03:32:07 +00:00
|
|
|
|
2014-07-25 10:53:07 +00:00
|
|
|
|
2014-11-13 01:51:49 +00:00
|
|
|
@hook("cmd_hook", "tcode")
|
|
|
|
def cmd_tcode(msg):
|
|
|
|
if len(msg.cmds) != 2:
|
|
|
|
raise IRCException("indicate a transaction code or "
|
|
|
|
"a keyword to search!")
|
|
|
|
|
|
|
|
url = ("http://www.tcodesearch.com/tcodes/search?q=%s" %
|
|
|
|
urllib.parse.quote(msg.cmds[1]))
|
|
|
|
page = web.getURLContent(url)
|
|
|
|
|
|
|
|
res = Response(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%s\x0F - %s" % (tcode.group(1),
|
|
|
|
striphtml(tcode.group(2))))
|
|
|
|
|
|
|
|
return res
|