mirror of
https://github.com/jlu5/SupyPlugins.git
synced 2025-04-26 04:51:08 -05:00
Wikifetch: cleanup redirect handling; fix tests
I also remove the showRedirects logic as the addition text is usually far too verbose for IRC
This commit is contained in:
parent
fb877f94bc
commit
b2d800ce61
@ -55,8 +55,5 @@ Wikifetch = conf.registerPlugin('Wikifetch')
|
||||
conf.registerChannelValue(Wikifetch, 'url',
|
||||
registry.String(_('en.wikipedia.org'), _("""Default URL of the
|
||||
website to pull from.""")))
|
||||
conf.registerChannelValue(Wikifetch, 'showRedirects',
|
||||
registry.Boolean(True, _("""Determines whether redirect paths will
|
||||
be shown in the output.""")))
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||
|
@ -143,19 +143,7 @@ class Wikifetch(callbacks.Plugin):
|
||||
self.log.debug('Wikifetch: following search result:')
|
||||
tree, article, addr = self._get_article_tree(None, searchresults[0].get('href'))
|
||||
search = redirect
|
||||
# otherwise, simply return the title and whether it redirected
|
||||
elif self.registryValue('showRedirects', msg.args[0]):
|
||||
redirect = re.search(r'\(%s <a href=[^>]*>([^<]*)</a>\)' %
|
||||
_('Redirected from'), article)
|
||||
if redirect:
|
||||
try:
|
||||
redirect = tree.xpath('//span[@class="mw-redirectedfrom"]/a')[0]
|
||||
redirect = redirect.text_content().strip()
|
||||
title = tree.xpath('//*[@class="firstHeading"]')
|
||||
title = title[0].text_content().strip()
|
||||
reply += '"%s" (Redirected from "%s"): ' % (title, redirect)
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
# extract the address we got it from - most sites have the perm link
|
||||
# inside the page itself
|
||||
try:
|
||||
|
@ -66,9 +66,8 @@ if network:
|
||||
self.assertNotError('wiki GNU/Linux')
|
||||
self.assertNotError('wiki --site en.wikipedia.org /')
|
||||
|
||||
def testRedirects(self):
|
||||
self.assertRegexp('wiki Foo', '"Foobar" \(Redirected from "Foo"\): '
|
||||
'The terms \x02foobar\x02')
|
||||
def testFollowRedirects(self):
|
||||
self.assertRegexp('wiki YVR', 'Vancouver International Airport')
|
||||
|
||||
def testWikiBold(self):
|
||||
self.assertRegexp('wiki Apple', '\x02')
|
||||
|
Loading…
x
Reference in New Issue
Block a user