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
|
2012-01-03 14:09:34 -05:00
|
|
|
author: mutantmonkey <mutantmonkey@mutantmonkey.in>
|
2011-02-14 18:38:12 -05:00
|
|
|
"""
|
|
|
|
|
2011-09-22 14:17:27 -04:00
|
|
|
import re, urllib.request, urllib.parse, urllib.error
|
2012-06-14 00:58:31 -04:00
|
|
|
import wiki
|
2011-02-14 18:38:12 -05:00
|
|
|
|
2012-06-14 00:58:31 -04:00
|
|
|
wikiapi = 'https://wiki.archlinux.org/api.php?action=query&list=search&srsearch={0}&limit=1&prop=snippet&format=json'
|
|
|
|
wikiuri = 'https://wiki.archlinux.org/index.php/{0}'
|
2011-02-14 18:38:12 -05:00
|
|
|
wikisearch = 'https://wiki.archlinux.org/index.php/Special:Search?' \
|
2012-06-14 00:58:31 -04:00
|
|
|
+ 'search={0}&fulltext=Search'
|
2011-02-14 18:38:12 -05:00
|
|
|
|
|
|
|
def awik(phenny, input):
|
2011-07-15 13:43:27 -04:00
|
|
|
origterm = input.groups()[1]
|
|
|
|
if not origterm:
|
|
|
|
return phenny.say('Perhaps you meant ".awik dwm"?')
|
2011-02-14 18:38:12 -05:00
|
|
|
|
2011-09-22 14:17:27 -04:00
|
|
|
term = urllib.parse.unquote(origterm)
|
2011-07-15 13:43:27 -04:00
|
|
|
term = term[0].upper() + term[1:]
|
|
|
|
term = term.replace(' ', '_')
|
2011-02-14 18:38:12 -05:00
|
|
|
|
2012-06-14 00:58:31 -04:00
|
|
|
w = wiki.Wiki(wikiapi, wikiuri, wikisearch)
|
|
|
|
|
|
|
|
try:
|
|
|
|
result = w.search(term)
|
2011-07-15 13:43:27 -04:00
|
|
|
except IOError:
|
2012-06-14 00:58:31 -04:00
|
|
|
error = "Can't connect to wiki.archlinux.org ({0})".format(wikiuri.format(term))
|
2011-07-15 13:43:27 -04:00
|
|
|
return phenny.say(error)
|
2011-02-14 18:38:12 -05:00
|
|
|
|
2011-07-15 13:43:27 -04:00
|
|
|
if result is not None:
|
|
|
|
phenny.say(result)
|
2012-06-14 00:58:31 -04:00
|
|
|
else:
|
|
|
|
phenny.say('Can\'t find anything in the ArchWiki for "{0}".'.format(origterm))
|
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())
|