Wikipedia: Add Python 3 compatibility.
parent
326b1438ab
commit
31fae1f2d8
|
@ -55,6 +55,11 @@ except:
|
||||||
_ = lambda x:x
|
_ = lambda x:x
|
||||||
internationalizeDocstring = lambda x:x
|
internationalizeDocstring = lambda x:x
|
||||||
|
|
||||||
|
if sys.version_info[0] >= 3:
|
||||||
|
quote_plus = urllib.parse.quote_plus
|
||||||
|
else:
|
||||||
|
quote_plus = urllib.quote_plus
|
||||||
|
|
||||||
|
|
||||||
class Wikipedia(callbacks.Plugin):
|
class Wikipedia(callbacks.Plugin):
|
||||||
"""Add the help for "@plugin help Wikipedia" here
|
"""Add the help for "@plugin help Wikipedia" here
|
||||||
|
@ -71,8 +76,10 @@ class Wikipedia(callbacks.Plugin):
|
||||||
# first, we get the page
|
# first, we get the page
|
||||||
addr = 'https://%s/wiki/Special:Search?search=%s' % \
|
addr = 'https://%s/wiki/Special:Search?search=%s' % \
|
||||||
(self.registryValue('url', msg.args[0]),
|
(self.registryValue('url', msg.args[0]),
|
||||||
urllib.quote_plus(search))
|
quote_plus(search))
|
||||||
article = utils.web.getUrl(addr)
|
article = utils.web.getUrl(addr)
|
||||||
|
if sys.version_info[0] >= 3:
|
||||||
|
article = article.decode()
|
||||||
# parse the page
|
# parse the page
|
||||||
tree = lxml.html.document_fromstring(article)
|
tree = lxml.html.document_fromstring(article)
|
||||||
# check if it gives a "Did you mean..." redirect
|
# check if it gives a "Did you mean..." redirect
|
||||||
|
@ -85,6 +92,8 @@ class Wikipedia(callbacks.Plugin):
|
||||||
addr = self.registryValue('url', msg.args[0]) + \
|
addr = self.registryValue('url', msg.args[0]) + \
|
||||||
didyoumean[0].get('href')
|
didyoumean[0].get('href')
|
||||||
article = utils.web.getUrl(addr)
|
article = utils.web.getUrl(addr)
|
||||||
|
if sys.version_info[0] >= 3:
|
||||||
|
article = article.decode()
|
||||||
tree = lxml.html.document_fromstring(article)
|
tree = lxml.html.document_fromstring(article)
|
||||||
search = redirect
|
search = redirect
|
||||||
# check if it's a page of search results (rather than an article), and
|
# check if it's a page of search results (rather than an article), and
|
||||||
|
@ -97,6 +106,8 @@ class Wikipedia(callbacks.Plugin):
|
||||||
addr = self.registryValue('url', msg.args[0]) + \
|
addr = self.registryValue('url', msg.args[0]) + \
|
||||||
searchresults[0].get('href')
|
searchresults[0].get('href')
|
||||||
article = utils.web.getUrl(addr)
|
article = utils.web.getUrl(addr)
|
||||||
|
if sys.version_info[0] >= 3:
|
||||||
|
article = article.decode()
|
||||||
tree = lxml.html.document_fromstring(article)
|
tree = lxml.html.document_fromstring(article)
|
||||||
search = redirect
|
search = redirect
|
||||||
# otherwise, simply return the title and whether it redirected
|
# otherwise, simply return the title and whether it redirected
|
||||||
|
@ -137,6 +148,7 @@ class Wikipedia(callbacks.Plugin):
|
||||||
p = p[0]
|
p = p[0]
|
||||||
p = p.text_content()
|
p = p.text_content()
|
||||||
p = p.strip()
|
p = p.strip()
|
||||||
|
if sys.version_info[0] < 3:
|
||||||
p = p.encode('utf-8')
|
p = p.encode('utf-8')
|
||||||
reply += '%s %s' % (p, ircutils.bold(addr))
|
reply += '%s %s' % (p, ircutils.bold(addr))
|
||||||
irc.reply(reply)
|
irc.reply(reply)
|
||||||
|
|
Loading…
Reference in New Issue