/usr/lib/python2.7/dist-packages/gplugs/wowwiki.py is in gozerbot 0.99.1-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | # plugs/wowwiki.py
#
#
__copyright__ = 'this file is in the public domain'
from gozerbot.generic import geturl, striphtml, splittxt, handle_exception, \
fromenc
from gozerbot.commands import cmnds
from gozerbot.aliases import aliases
from gozerbot.examples import examples
from gozerbot.utils.rsslist import rsslist
from gozerbot.plughelp import plughelp
from urllib import quote
import re
plughelp.add('wowwiki', 'query wowwiki')
wikire = re.compile('start content(.*?)end content', re.M)
def getwikidata(url, ievent):
""" fetch wiki data """
try:
result = fromenc(geturl(url))
except IOError, ex:
try:
errno = ex[0]
except IndexError:
handle_exception(ievent=ievent)
return
ievent.reply('invalid option')
return
if not result:
ievent.reply("can't find data for %s" % url)
return
res = rsslist(result)
txt = ""
for i in res:
try:
txt = i['text']
break
except:
pass
if not txt:
ievent.reply("no data found on %s" % url)
return
#txt = re.sub('\[\[Image:([^\[\]]+|\[\[[^\]]+\]\])*\]\]', '', txt)
txt = txt.replace('[[', '')
txt = txt.replace(']]', '')
txt = re.sub('\s+', ' ', txt)
return txt
def handle_wowwiki(bot, ievent):
""" wikipedia <what> .. search wikipedia for <what> """
if not ievent.rest:
ievent.missing('<what>')
return
what = ""
lang = 'en'
for i in ievent.rest.split():
first = i[0].upper()
rest = i[1:]
if i.startswith('-'):
if len(i) != 3:
ievent.reply('invalid option')
return
lang = i[1:]
continue
what += "%s%s " % (first, rest)
what = what.strip().replace(' ', '_')
url = 'http://wowwiki.com/wiki/Special:Export/%s' % quote(what.encode('utf-8'))
url2 = 'http://wowwiki.com/wiki/%s' % quote(what.encode('utf-8'))
txt = getwikidata(url, ievent)
if not txt:
return
if '#REDIRECT' in txt or '#redirect' in txt:
redir = ' '.join(txt.split()[1:])
url = 'http://wowwiki.com/wiki/Special:Export/%s' % quote(redir.encode('utf-8'))
url2 = 'http://wowwiki.com/wiki/%s' % quote(redir.encode('utf-8'))
txt = getwikidata(url, ievent)
if not txt:
return
res = ['%s ===> ' % url2, ]
res += splittxt(striphtml(txt).strip())
ievent.reply(res)
cmnds.add('wowwiki', handle_wowwiki, 'USER')
examples.add('wowwiki', 'wowwiki <what> .. search wowwiki for <what>','1) wowwiki \
gozerbot')
aliases.data['wow'] = 'wowwiki'
|