wikipedia.py: If the command is used without arguments, fetch a random page
This commit is contained in:
parent
2fd1def5f4
commit
f4accb15e5
|
@ -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 <phrase> -- gets first sentence of wikipedia ''' \
|
||||
'''article on <phrase>'''
|
||||
|
||||
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}'
|
||||
|
|
Loading…
Reference in New Issue