1
0
Fork 0
nemubot/modules/sap.py

44 lines
1.1 KiB
Python
Raw Normal View History

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"""
import urllib.parse
2015-05-23 21:46:46 +00:00
import urllib.request
from bs4 import BeautifulSoup
from nemubot.exception import IMException
from nemubot.hooks import hook
from nemubot.tools import web
2014-07-24 03:32:07 +00:00
nemubotversion = 4.0
2014-07-24 03:32:07 +00:00
from nemubot.module.more import Response
2014-07-24 03:32:07 +00:00
2014-11-13 01:51:49 +00:00
def help_full():
2015-05-23 21:46:46 +00:00
return "Retrieve SAP transaction codes and details using tcodes or keywords: !tcode <transaction code|keywords>"
2014-07-24 03:32:07 +00:00
2015-11-02 19:19:12 +00:00
@hook.command("tcode")
2014-11-13 01:51:49 +00:00
def cmd_tcode(msg):
if not len(msg.args):
raise IMException("indicate a transaction code or "
2014-11-13 01:51:49 +00:00
"a keyword to search!")
url = ("http://www.tcodesearch.com/tcodes/search?q=%s" %
urllib.parse.quote(msg.args[0]))
2015-05-23 21:46:46 +00:00
2014-11-13 01:51:49 +00:00
page = web.getURLContent(url)
2015-05-23 21:46:46 +00:00
soup = BeautifulSoup(page)
2014-11-13 01:51:49 +00:00
res = Response(channel=msg.channel,
nomore="No more transaction code",
count=" (%d more tcodes)")
2015-05-23 21:46:46 +00:00
search_res = soup.find("", {'id':'searchresults'})
for item in search_res.find_all('dd'):
res.append_message(item.get_text().split('\n')[1].strip())
2014-11-13 01:51:49 +00:00
return res