diff options
author | Sean B. Palmer <sbp@aldebaran.local> | 2011-03-10 13:41:02 +0000 |
---|---|---|
committer | Sean B. Palmer <sbp@aldebaran.local> | 2011-03-10 13:41:02 +0000 |
commit | 5bc5662108b84def160043302188e3ade768e05b (patch) | |
tree | 31c8f09ed7a3eff4b9b157b7daa2c5fa71a14f8f /modules/search.py | |
parent | ecb8af1bbea0dee31903b1e962c0b731f2d36318 (diff) | |
download | bot-5bc5662108b84def160043302188e3ade768e05b.tar.gz bot-5bc5662108b84def160043302188e3ade768e05b.tar.bz2 bot-5bc5662108b84def160043302188e3ade768e05b.zip |
Couple of fixes from ayust on github, thanks
Diffstat (limited to 'modules/search.py')
-rwxr-xr-x | modules/search.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/modules/search.py b/modules/search.py index 7a0e3ad..1067531 100755 --- a/modules/search.py +++ b/modules/search.py @@ -86,5 +86,31 @@ def gcs(phenny, input): phenny.say(reply) gcs.commands = ['gcs', 'comp'] +r_bing = re.compile(r'<h3><a href="([^"]+)"') + +def bing(phenny, input): + """Queries Bing for the specified input.""" + query = input.group(2) + if query.startswith(':'): + lang, query = query.split(' ', 1) + lang = lang[1:] + else: lang = 'en-GB' + if not query: + return phenny.reply('.bing what?') + + query = web.urllib.quote(query.encode('utf-8')) + base = 'http://www.bing.com/search?mkt=%s&q=' % lang + bytes = web.get(base + query) + m = r_bing.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) +bing.commands = ['bing'] +bing.example = '.bing swhack' + if __name__ == '__main__': print __doc__.strip() |