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 re
|
2014-12-17 06:32:34 +00:00
|
|
|
import urllib.parse
|
2015-05-23 21:46:46 +00:00
|
|
|
import urllib.request
|
|
|
|
from bs4 import BeautifulSoup
|
2014-08-12 18:10:19 +00:00
|
|
|
|
2015-01-04 22:57:09 +00:00
|
|
|
from nemubot.exception import IRCException
|
2015-01-03 19:34:44 +00:00
|
|
|
from nemubot.hooks import hook
|
|
|
|
from nemubot.tools import web
|
|
|
|
from nemubot.tools.web import striphtml
|
2014-07-24 03:32:07 +00:00
|
|
|
|
2015-06-03 20:07:06 +00:00
|
|
|
nemubotversion = 4.0
|
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():
|
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
|
|
|
|
2014-07-25 10:53:07 +00:00
|
|
|
|
2014-11-13 01:51:49 +00:00
|
|
|
@hook("cmd_hook", "tcode")
|
|
|
|
def cmd_tcode(msg):
|
2015-06-03 20:07:06 +00:00
|
|
|
if not len(msg.args):
|
2014-11-13 01:51:49 +00:00
|
|
|
raise IRCException("indicate a transaction code or "
|
|
|
|
"a keyword to search!")
|
|
|
|
|
|
|
|
url = ("http://www.tcodesearch.com/tcodes/search?q=%s" %
|
2015-06-03 20:07:06 +00:00
|
|
|
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
|