DuckDuckGo support, and minor wa and wik fixes.

master
Sean B. Palmer 2011-08-04 15:53:55 +01:00
parent c493e7ca07
commit 66edd83372
3 changed files with 21 additions and 2 deletions

View File

@ -105,7 +105,7 @@ def wa(phenny, input):
return phenny.reply("No search term.")
query = input.group(2).encode('utf-8')
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:
phenny.say(answer)
else: phenny.reply('Sorry, no result.')

View File

@ -129,5 +129,24 @@ def bing(phenny, input):
bing.commands = ['bing']
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__':
print __doc__.strip()

View File

@ -24,7 +24,7 @@ r_redirect = re.compile(
abbrs = ['etc', 'ca', 'cf', 'Co', 'Ltd', 'Inc', 'Mt', 'Mr', 'Mrs',
'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')
t_sentence = r'^.{5,}?(?<!\b%s)(?:\.(?=[\[ ][A-Z0-9]|\Z)|\Z)'