1
0
Fork 0

Added SAP tcode lookup module

This commit is contained in:
Max 2014-07-24 05:32:07 +02:00
parent 411d8cdc41
commit be80e84323
2 changed files with 43 additions and 0 deletions

View File

@ -23,5 +23,6 @@
<load path="syno" />
<load path="man" />
<load path="reddit" />
<load path="sap" />
</nemubotconfig>

42
modules/sap.py Normal file
View File

@ -0,0 +1,42 @@
# coding=utf-8
import urllib.request
import json
import re
from tools import web
from tools.web import striphtml
nemubotversion = 3.3
def help_tiny ():
return "Find information about an SAP transaction codes"
def help_full ():
return "!tcode <transaction code|keywords>"
def load(context):
from hooks import Hook
add_hook("cmd_hook", Hook(cmd_tcode, "tcode"))
def cmd_tcode(msg):
if (len(msg.cmds) < 2):
return Response(msg.sender,
"Demande incorrecte.\n %s" % help_full(),
msg.channel)
res = Response(msg.sender, None, msg.channel)
request = urllib.parse.quote(msg.cmds[1])
url = "http://www.tcodesearch.com/tcodes/search?q=" + request
page = web.getURLContent(url)
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