Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Description:
- # A way to interact with the Google Web API.
- #
- # Commands:
- # hubot google|g <query> - Queries Google Web for <query> and returns the first result.
- #
- # Author:
- # leathan
- scrape = require('scrapeit')
- module.exports = (robot) ->
- robot.hear /^(g|google) (.*)/i, (msg) ->
- googleMe msg, msg.match[2], (url) ->
- msg.send url
- googleMe = (msg, query, cb) ->
- scrape "https://www.google.com/search?q=#{encodeURIComponent(msg.match[2])}", (err, o, dom) ->
- data = o('.r a')[0].data.slice(15)
- data = data.slice(0, data.indexOf('&'))
- cb "#{decodeURIComponent(data)}";
Add Comment
Please, Sign In to add comment