diff options
author | Sean B. Palmer <sean@miscoranda.com> | 2011-08-04 15:53:55 +0100 |
---|---|---|
committer | Sean B. Palmer <sean@miscoranda.com> | 2011-08-04 15:53:55 +0100 |
commit | 66edd833726d0a14400df65311999b1496b9f8cb (patch) | |
tree | 76ea94f6c23c7b2819a42a74f1036ff6220d9222 /modules/search.py | |
parent | c493e7ca07cca403334eabcc069d5bc1cb468220 (diff) | |
download | bot-66edd833726d0a14400df65311999b1496b9f8cb.tar.gz bot-66edd833726d0a14400df65311999b1496b9f8cb.tar.bz2 bot-66edd833726d0a14400df65311999b1496b9f8cb.zip |
DuckDuckGo support, and minor wa and wik fixes.
Diffstat (limited to 'modules/search.py')
-rwxr-xr-x | modules/search.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/modules/search.py b/modules/search.py index 2751bb5..c8f9a6a 100755 --- a/modules/search.py +++ b/modules/search.py @@ -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() |