From f4accb15e5831143c157033933ffa5e6fc3ca90a Mon Sep 17 00:00:00 2001 From: Chris Swetenham Date: Wed, 21 May 2014 20:44:35 +0800 Subject: [PATCH] wikipedia.py: If the command is used without arguments, fetch a random page --- plugins/wikipedia.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/wikipedia.py b/plugins/wikipedia.py index e4f92a1..7113a79 100644 --- a/plugins/wikipedia.py +++ b/plugins/wikipedia.py @@ -5,19 +5,23 @@ import re from util import hook, http - api_prefix = "http://en.wikipedia.org/w/api.php" search_url = api_prefix + "?action=opensearch&format=xml" +random_url = api_prefix + "?action=query&format=xml&list=random&rnlimit=1&rnnamespace=0" paren_re = re.compile('\s*\(.*\)$') @hook.command('w') -@hook.command +@hook.command(autohelp=False) def wiki(inp): '''.w/.wiki -- gets first sentence of wikipedia ''' \ '''article on ''' + if inp == "": + r = http.get_xml(random_url) + inp = r.find('.//page').get('title') + x = http.get_xml(search_url, search=inp) ns = '{http://opensearch.org/searchsuggest2}'