phenny-1/modules/vtluugwiki.py

49 lines
1.3 KiB
Python
Raw Normal View History

2010-12-21 00:22:25 -05:00
#!/usr/bin/env python
"""
vtluugwiki.py - Phenny VTLUUG Wiki 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>
2010-12-21 00:22:25 -05:00
"""
2013-06-09 01:27:24 -04:00
import re
import web
import wiki
2010-12-21 00:22:25 -05:00
wikiapi = 'https://vtluug.org/w/api.php?action=query&list=search&srsearch={0}&limit=1&prop=snippet&format=json'
wikiuri = 'https://vtluug.org/wiki/{0}'
2011-02-13 19:01:12 -05:00
wikisearch = 'https://vtluug.org/wiki/Special:Search?' \
+ 'search={0}&fulltext=Search'
2010-12-21 00:22:25 -05:00
def vtluug(phenny, input):
2011-07-15 13:43:27 -04:00
origterm = input.groups()[1]
if not origterm:
return phenny.say('Perhaps you meant ".vtluug VT-Wireless"?')
2010-12-21 00:22:25 -05:00
2013-06-09 01:27:24 -04:00
term = web.unquote(origterm)
2011-07-15 13:43:27 -04:00
term = term[0].upper() + term[1:]
term = term.replace(' ', '_')
2010-12-21 00:22:25 -05:00
w = wiki.Wiki(wikiapi, wikiuri, wikisearch)
try:
result = w.search(term)
2013-06-09 01:27:24 -04:00
except web.ConnectionError:
error = "Can't connect to vtluug.org ({0})".format(wikiuri.format(term))
2011-07-15 13:43:27 -04:00
return phenny.say(error)
2010-12-21 00:22:25 -05:00
2011-07-15 13:43:27 -04:00
if result is not None:
phenny.say(result)
else:
phenny.say('Can\'t find anything in the VTLUUG Wiki for "{0}".'.format(origterm))
2010-12-21 00:22:25 -05:00
vtluug.commands = ['vtluug']
vtluug.priority = 'high'
if __name__ == '__main__':
2011-09-22 14:17:27 -04:00
print(__doc__.strip())