commit
56772b05a3
|
@ -105,7 +105,7 @@ def wa(phenny, input):
|
||||||
return phenny.reply("No search term.")
|
return phenny.reply("No search term.")
|
||||||
query = input.group(2).encode('utf-8')
|
query = input.group(2).encode('utf-8')
|
||||||
uri = 'http://tumbolia.appspot.com/wa/'
|
uri = 'http://tumbolia.appspot.com/wa/'
|
||||||
answer = web.get(uri + web.urllib.quote(query))
|
answer = web.get(uri + web.urllib.quote(query.replace('+', '%2B')))
|
||||||
if answer:
|
if answer:
|
||||||
phenny.say(answer)
|
phenny.say(answer)
|
||||||
else: phenny.reply('Sorry, no result.')
|
else: phenny.reply('Sorry, no result.')
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
"""
|
|
||||||
dict.py - Phenny Dictionary Module
|
|
||||||
Copyright 2008-9, Sean B. Palmer, inamidst.com
|
|
||||||
Licensed under the Eiffel Forum License 2.
|
|
||||||
|
|
||||||
http://inamidst.com/phenny/
|
|
||||||
"""
|
|
||||||
|
|
||||||
import re, urllib
|
|
||||||
import web
|
|
||||||
from tools import deprecated
|
|
||||||
|
|
||||||
r_li = re.compile(r'(?ims)<li>.*?</li>')
|
|
||||||
r_tag = re.compile(r'<[^>]+>')
|
|
||||||
r_parens = re.compile(r'(?<=\()(?:[^()]+|\([^)]+\))*(?=\))')
|
|
||||||
r_word = re.compile(r'^[A-Za-z0-9\' -]+$')
|
|
||||||
|
|
||||||
uri = 'http://encarta.msn.com/dictionary_/%s.html'
|
|
||||||
r_info = re.compile(
|
|
||||||
r'(?:ResultBody"><br /><br />(.*?) )|(?:<b>(.*?)</b>)'
|
|
||||||
)
|
|
||||||
|
|
||||||
def dict(phenny, input):
|
|
||||||
if not input.group(2):
|
|
||||||
return phenny.reply("Nothing to define.")
|
|
||||||
word = input.group(2)
|
|
||||||
word = urllib.quote(word.encode('utf-8'))
|
|
||||||
|
|
||||||
def trim(thing):
|
|
||||||
if thing.endswith(' '):
|
|
||||||
thing = thing[:-6]
|
|
||||||
return thing.strip(' :.')
|
|
||||||
|
|
||||||
bytes = web.get(uri % word)
|
|
||||||
results = {}
|
|
||||||
wordkind = None
|
|
||||||
for kind, sense in r_info.findall(bytes):
|
|
||||||
kind, sense = trim(kind), trim(sense)
|
|
||||||
if kind: wordkind = kind
|
|
||||||
elif sense:
|
|
||||||
results.setdefault(wordkind, []).append(sense)
|
|
||||||
result = input.group(2).encode('utf-8') + ' - '
|
|
||||||
for key in sorted(results.keys()):
|
|
||||||
if results[key]:
|
|
||||||
result += (key or '') + ' 1. ' + results[key][0]
|
|
||||||
if len(results[key]) > 1:
|
|
||||||
result += ', 2. ' + results[key][1]
|
|
||||||
result += '; '
|
|
||||||
result = result.rstrip('; ')
|
|
||||||
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()
|
|
|
@ -129,5 +129,24 @@ def bing(phenny, input):
|
||||||
bing.commands = ['bing']
|
bing.commands = ['bing']
|
||||||
bing.example = '.bing swhack'
|
bing.example = '.bing swhack'
|
||||||
|
|
||||||
|
r_ddg = re.compile(r'nofollow" class="[^"]+" href="(.*?)">')
|
||||||
|
|
||||||
|
def ddg(phenny, input):
|
||||||
|
query = input.group(2)
|
||||||
|
if not query: return phenny.reply('.ddg what?')
|
||||||
|
|
||||||
|
query = web.urllib.quote(query.encode('utf-8'))
|
||||||
|
uri = 'http://duckduckgo.com/html/?q=%s&kl=uk-en' % query
|
||||||
|
bytes = web.get(uri)
|
||||||
|
m = r_ddg.search(bytes)
|
||||||
|
if m:
|
||||||
|
uri = m.group(1)
|
||||||
|
phenny.reply(uri)
|
||||||
|
if not hasattr(phenny.bot, 'last_seen_uri'):
|
||||||
|
phenny.bot.last_seen_uri = {}
|
||||||
|
phenny.bot.last_seen_uri[input.sender] = uri
|
||||||
|
else: phenny.reply("No results found for '%s'." % query)
|
||||||
|
ddg.commands = ['ddg']
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print __doc__.strip()
|
print __doc__.strip()
|
||||||
|
|
|
@ -7,7 +7,7 @@ Licensed under the Eiffel Forum License 2.
|
||||||
http://inamidst.com/phenny/
|
http://inamidst.com/phenny/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import re, urllib
|
import re, urllib, gzip, StringIO
|
||||||
import web
|
import web
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ r_redirect = re.compile(
|
||||||
|
|
||||||
abbrs = ['etc', 'ca', 'cf', 'Co', 'Ltd', 'Inc', 'Mt', 'Mr', 'Mrs',
|
abbrs = ['etc', 'ca', 'cf', 'Co', 'Ltd', 'Inc', 'Mt', 'Mr', 'Mrs',
|
||||||
'Dr', 'Ms', 'Rev', 'Fr', 'St', 'Sgt', 'pron', 'approx', 'lit',
|
'Dr', 'Ms', 'Rev', 'Fr', 'St', 'Sgt', 'pron', 'approx', 'lit',
|
||||||
'syn', 'transl', 'sess', 'fl', 'Op', 'Dec'] \
|
'syn', 'transl', 'sess', 'fl', 'Op', 'Dec', 'Brig', 'Gen'] \
|
||||||
+ list('ABCDEFGHIJKLMNOPQRSTUVWXYZ') \
|
+ list('ABCDEFGHIJKLMNOPQRSTUVWXYZ') \
|
||||||
+ list('abcdefghijklmnopqrstuvwxyz')
|
+ list('abcdefghijklmnopqrstuvwxyz')
|
||||||
t_sentence = r'^.{5,}?(?<!\b%s)(?:\.(?=[\[ ][A-Z0-9]|\Z)|\Z)'
|
t_sentence = r'^.{5,}?(?<!\b%s)(?:\.(?=[\[ ][A-Z0-9]|\Z)|\Z)'
|
||||||
|
|
|
@ -92,5 +92,9 @@ def w(phenny, input):
|
||||||
w.commands = ['w']
|
w.commands = ['w']
|
||||||
w.example = '.w bailiwick'
|
w.example = '.w bailiwick'
|
||||||
|
|
||||||
|
def encarta(phenny, input):
|
||||||
|
return phenny.reply('Microsoft removed Encarta, try .w instead!')
|
||||||
|
encarta.commands = ['dict']
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print __doc__.strip()
|
print __doc__.strip()
|
||||||
|
|
Loading…
Reference in New Issue