2008-02-21 07:06:33 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
"""
|
|
|
|
wikipedia.py - Phenny Wikipedia Module
|
2009-06-07 05:08:49 -04:00
|
|
|
Copyright 2008-9, Sean B. Palmer, inamidst.com
|
2008-02-21 07:06:33 -05:00
|
|
|
Licensed under the Eiffel Forum License 2.
|
|
|
|
|
|
|
|
http://inamidst.com/phenny/
|
|
|
|
"""
|
|
|
|
|
2012-06-14 00:58:31 -04:00
|
|
|
import wiki
|
2008-02-21 07:06:33 -05:00
|
|
|
|
2018-03-16 09:27:18 -04:00
|
|
|
endpoints = {
|
|
|
|
'api': 'https://en.wikipedia.org/w/api.php?format=json&action=query&list=search&srsearch={0}&prop=snippet&limit=1',
|
|
|
|
'url': 'https://en.wikipedia.org/wiki/{0}',
|
|
|
|
'search': 'https://en.wikipedia.org/wiki/Special:Search?search={0}&fulltext=Search',
|
|
|
|
}
|
2008-02-21 07:06:33 -05:00
|
|
|
|
|
|
|
def wik(phenny, input):
|
2013-10-05 19:20:37 -04:00
|
|
|
""".wik <term> - Look up something on Wikipedia."""
|
|
|
|
|
2011-07-15 13:43:27 -04:00
|
|
|
origterm = input.groups()[1]
|
|
|
|
if not origterm:
|
|
|
|
return phenny.say('Perhaps you meant ".wik Zen"?')
|
2008-02-23 07:16:43 -05:00
|
|
|
|
2018-03-16 09:27:18 -04:00
|
|
|
origterm = origterm.strip()
|
|
|
|
term, section = wiki.parse_term(origterm)
|
2008-02-21 07:06:33 -05:00
|
|
|
|
2018-03-16 09:27:18 -04:00
|
|
|
w = wiki.Wiki(endpoints)
|
|
|
|
match = w.search(term)
|
2012-06-14 00:58:31 -04:00
|
|
|
|
2018-03-16 09:27:18 -04:00
|
|
|
if not match:
|
2012-06-14 00:58:31 -04:00
|
|
|
phenny.say('Can\'t find anything in Wikipedia for "{0}".'.format(origterm))
|
2018-03-16 09:27:18 -04:00
|
|
|
return
|
|
|
|
|
|
|
|
snippet, url = wiki.extract_snippet(match, section)
|
|
|
|
|
|
|
|
phenny.say('"{0}" - {1}'.format(snippet, url))
|
2008-02-21 07:06:33 -05:00
|
|
|
|
|
|
|
wik.commands = ['wik']
|
|
|
|
wik.priority = 'high'
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2011-09-22 14:17:27 -04:00
|
|
|
print(__doc__.strip())
|