summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean B. Palmer <sbp@aldebaran.local>2011-07-22 15:43:50 +0100
committerSean B. Palmer <sbp@aldebaran.local>2011-07-22 15:43:50 +0100
commitf329429de4b0d7561527d419cd1307eaf38f1cb3 (patch)
tree3e5aad226369458f2e324a81e3a30afd70d5e84b
parent7dbddc8429d0b238f64acabab435d27472ced062 (diff)
downloadbot-f329429de4b0d7561527d419cd1307eaf38f1cb3.tar.gz
bot-f329429de4b0d7561527d419cd1307eaf38f1cb3.tar.bz2
bot-f329429de4b0d7561527d419cd1307eaf38f1cb3.zip
Support for gzip encoding from Wikipedia.
-rwxr-xr-xmodules/dict.py1
-rwxr-xr-xmodules/wikipedia.py9
-rwxr-xr-xmodules/wiktionary.py4
3 files changed, 12 insertions, 2 deletions
diff --git a/modules/dict.py b/modules/dict.py
index 8f13e99..8fa6182 100755
--- a/modules/dict.py
+++ b/modules/dict.py
@@ -51,7 +51,6 @@ def dict(phenny, input):
if result.endswith('-') and (len(result) < 30):
phenny.reply('Sorry, no definition found.')
else: phenny.say(result)
-dict.commands = ['dict']
if __name__ == '__main__':
print __doc__.strip()
diff --git a/modules/wikipedia.py b/modules/wikipedia.py
index b476ba3..4ad0113 100755
--- a/modules/wikipedia.py
+++ b/modules/wikipedia.py
@@ -7,7 +7,7 @@ Licensed under the Eiffel Forum License 2.
http://inamidst.com/phenny/
"""
-import re, urllib
+import re, urllib, gzip, StringIO
import web
wikiuri = 'http://%s.wikipedia.org/wiki/%s'
@@ -69,6 +69,13 @@ def wikipedia(term, language='en', last=False):
u = wikiuri % (language, q)
bytes = web.get(u)
else: bytes = web.get(wikiuri % (language, term))
+
+ if bytes.startswith('\x1f\x8b\x08\x00\x00\x00\x00\x00'):
+ f = StringIO.StringIO(bytes)
+ f.seek(0)
+ gzip_file = gzip.GzipFile(fileobj=f)
+ bytes = gzip_file.read()
+
bytes = r_tr.sub('', bytes)
if not last:
diff --git a/modules/wiktionary.py b/modules/wiktionary.py
index 4a5f407..9229194 100755
--- a/modules/wiktionary.py
+++ b/modules/wiktionary.py
@@ -92,5 +92,9 @@ def w(phenny, input):
w.commands = ['w']
w.example = '.w bailiwick'
+def encarta(phenny, input):
+ return phenny.reply('Microsoft removed Encarta, try .w instead!')
+encarta.commands = ['dict']
+
if __name__ == '__main__':
print __doc__.strip()