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
|
from util import hook, http
|
||||||
|
|
||||||
|
|
||||||
api_prefix = "http://en.wikipedia.org/w/api.php"
|
api_prefix = "http://en.wikipedia.org/w/api.php"
|
||||||
search_url = api_prefix + "?action=opensearch&format=xml"
|
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*\(.*\)$')
|
paren_re = re.compile('\s*\(.*\)$')
|
||||||
|
|
||||||
|
|
||||||
@hook.command('w')
|
@hook.command('w')
|
||||||
@hook.command
|
@hook.command(autohelp=False)
|
||||||
def wiki(inp):
|
def wiki(inp):
|
||||||
'''.w/.wiki <phrase> -- gets first sentence of wikipedia ''' \
|
'''.w/.wiki <phrase> -- gets first sentence of wikipedia ''' \
|
||||||
'''article on <phrase>'''
|
'''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)
|
x = http.get_xml(search_url, search=inp)
|
||||||
|
|
||||||
ns = '{http://opensearch.org/searchsuggest2}'
|
ns = '{http://opensearch.org/searchsuggest2}'
|
||||||
|
|
Loading…
Reference in New Issue