mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-13 06:59:53 -05:00
test
This commit is contained in:
parent
1aa68fe21a
commit
17789c120a
@ -14,22 +14,22 @@ from lxml import html
|
|||||||
|
|
||||||
api_url = 'https://httpstatuses.com/'
|
api_url = 'https://httpstatuses.com/'
|
||||||
basic_xpath = "/html/body/article/h1[1]/text()"
|
basic_xpath = "/html/body/article/h1[1]/text()"
|
||||||
|
explain_xpath = "/html/body/article/p[1]/text()"
|
||||||
|
|
||||||
|
|
||||||
@SpiceBot.prerun('module')
|
@SpiceBot.prerun('module')
|
||||||
@sopel.module.commands('httpcode')
|
@sopel.module.commands('httpcode')
|
||||||
def bot_command_http_codes(bot, trigger, botcom):
|
def bot_command_http_codes(bot, trigger, botcom):
|
||||||
|
|
||||||
query = spicemanip(botcom.dict["args"], 1) or None
|
query = spicemanip(botcom.dict["args"], 1) or None
|
||||||
if not query:
|
if not query:
|
||||||
return bot.osd("You must provide a HTTP status code to look up.")
|
return bot.osd("You must provide a HTTP status code to look up.")
|
||||||
|
message = ["[HTTP code search for " + str(query) + "]"]
|
||||||
result = fetch_result(str(query))
|
result = fetch_result(str(query))
|
||||||
|
message.extend(result)
|
||||||
bot.osd(["[HTTP code search for " + str(query) + "]", result])
|
bot.osd(message)
|
||||||
|
|
||||||
|
|
||||||
def fetch_result(query):
|
def fetch_result(query):
|
||||||
|
|
||||||
if not re.match('^[1-5]\d{2}$', query):
|
if not re.match('^[1-5]\d{2}$', query):
|
||||||
return "Invalid HTTP status code: %s" % query
|
return "Invalid HTTP status code: %s" % query
|
||||||
url = api_url + query
|
url = api_url + query
|
||||||
@ -49,18 +49,26 @@ def fetch_result(query):
|
|||||||
return "HTTP error: " + e.message
|
return "HTTP error: " + e.message
|
||||||
|
|
||||||
tree = html.fromstring(r.content)
|
tree = html.fromstring(r.content)
|
||||||
|
dispmsg = []
|
||||||
try:
|
try:
|
||||||
title = tree.xpath((basic_xpath))
|
title = tree.xpath((basic_xpath))
|
||||||
if isinstance(title, list):
|
if isinstance(title, list):
|
||||||
title = title[0]
|
title = title[0]
|
||||||
# title = str(title)
|
|
||||||
# for r in (("u'", ""), ("['", ""), ("[", ""), ("']", ""), ("\\n", ""), ("\\t", "")):
|
|
||||||
# title = title.replace(*r)
|
|
||||||
# title = unicode_string_cleanup(title)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
title = None
|
title = None
|
||||||
if title:
|
if title:
|
||||||
return str(title)
|
dispmsg.append(str(title))
|
||||||
else:
|
|
||||||
return "An Error Occured"
|
try:
|
||||||
|
explanation = tree.xpath((explain_xpath))
|
||||||
|
if isinstance(explanation, list):
|
||||||
|
explanation = explanation[0]
|
||||||
|
except Exception as e:
|
||||||
|
explanation = None
|
||||||
|
if explanation:
|
||||||
|
dispmsg.append(str(explanation))
|
||||||
|
|
||||||
|
if not len(dispmsg):
|
||||||
|
dispmsg.append("An Error Occured Finding This Information")
|
||||||
|
|
||||||
|
return dispmsg
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user