From 9f1f04d25c122ab2be551e44117eb04f0d4b5c7e Mon Sep 17 00:00:00 2001 From: James Lu Date: Fri, 27 Jan 2017 17:25:43 -0800 Subject: [PATCH] Wikifetch: only show "possible results" in disambiguation pages if parsing succeeds --- Wikifetch/plugin.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Wikifetch/plugin.py b/Wikifetch/plugin.py index 64bb539..e6857b2 100644 --- a/Wikifetch/plugin.py +++ b/Wikifetch/plugin.py @@ -177,20 +177,22 @@ class Wikifetch(callbacks.Plugin): tree.xpath('//table[@id="setindexbox"]') or \ tree.xpath('//div[contains(@class, "disambig")]') # Wikia (2017-01-27) if disambig: + reply += format(_('%u is a disambiguation page. '), addr) disambig = tree.xpath('//div[@id="bodyContent"]/div/ul/li') - # Hackishly bold all tags - r = [] + + disambig_results = [] for item in disambig: for link in item.findall('a'): if link.text is not None: + # Hackishly bold all tags link.text = "%s" % link.text item = item.text_content().replace('', '\x02') # Normalize and strip whitespace, to prevent newlines and such # from corrupting the display. item = utils.str.normalizeWhitespace(item).strip() - r.append(item) - reply += format(_('%u is a disambiguation page. ' - 'Possible results include: %L'), addr, r) + disambig_results.append(item) + if disambig_results: + reply += format(_('Possible results include: %L'), disambig_results) # Catch talk pages elif 'ns-talk' in tree.find("body").attrib['class']: