phenny/modules/archwiki.py

46 lines
1.2 KiB
Python
Raw Normal View History

2011-02-14 18:38:12 -05:00
#!/usr/bin/env python
"""
archwiki.py - Phenny ArchWiki Module
Copyright 2008-9, Sean B. Palmer, inamidst.com
Licensed under the Eiffel Forum License 2.
http://inamidst.com/phenny/
modified from Wikipedia module
author: mutantmonkey <mutantmonkey@mutantmonkey.in>
2011-02-14 18:38:12 -05:00
"""
import wiki
2011-02-14 18:38:12 -05:00
2018-03-16 09:27:18 -04:00
endpoints = {
'api': 'https://wiki.archlinux.org/api.php?action=query&list=search&srsearch={0}&limit=1&format=json',
'url': 'https://wiki.archlinux.org/index.php/{0}',
'search': 'https://wiki.archlinux.org/index.php/Special:Search?search={0}&fulltext=Search',
}
2011-02-14 18:38:12 -05:00
def awik(phenny, input):
2018-03-16 09:27:18 -04:00
""".awik <term> - Look up something on the ArchWiki."""
origterm = input.group(1)
if not origterm:
2011-07-15 13:43:27 -04:00
return phenny.say('Perhaps you meant ".awik dwm"?')
2011-02-14 18:38:12 -05:00
2018-03-16 09:27:18 -04:00
term, section = wiki.parse_term(origterm)
w = wiki.Wiki(endpoints)
match = w.search(term)
2011-02-14 18:38:12 -05:00
2018-03-16 09:27:18 -04:00
if not match:
phenny.say('Can\'t find anything in the ArchWiki for "{0}".'.format(term))
return
2018-03-16 09:27:18 -04:00
snippet, url = wiki.extract_snippet(match, section)
2011-02-14 18:38:12 -05:00
2018-03-16 09:27:18 -04:00
phenny.say('"{0}" - {1}'.format(snippet, url))
2011-02-14 18:38:12 -05:00
awik.commands = ['awik']
awik.priority = 'high'
if __name__ == '__main__':
2011-09-22 14:17:27 -04:00
print(__doc__.strip())