示例#1
0
function queryGoogle(query, cb) {
	google.resultsPerPage = 1;
	var url='site:en.wikipedia.org ' + query;
	google(url, function (err, next, links) {
		if (err) {
			if (err.status) {
				cb(new Error('Something went wrong while searching on Google: ' + err.status + ': ' + http['STATUS_CODES'][status]), null);
			} else {
				cb(new Error('Something went wrong while searching on Google: ' + err.message), null);
			}

			return;
		}

		if (links.length === 0) {
			cb(new Error('No results for: "' + query + '".'), null);

			return;
		}

		var match = parseLinks(links[0].link)[0];

		if (match && match[1]) {
			cb(null, match[1]);
		} else if (next) {
			next();
		} else {
			cb(new Error('No results for: "' + query + '".'), null);
		}
	});
}
示例#2
0
文件: func.js 项目: z0mbieparade/b0t
	goog(CHAN, search_string, callback){
		var _this = this;
		CHAN.log.debug('Searching GOOG');
		google(search_string, function (err, res){
			if(err){
				CHAN.log.error('goog:', err);
				if(err.message.match(/CAPTCHA/igm)) return callback({err: 'Slapped by Google CAPTCHA'});
				return callback({err: 'Something went wrong'});
			}
			
			var links = res.links.filter(link => link.title && link.href);

			if(links.length < 1) return callback({err: 'Nothing found.'});

			var say_link = links[0];

			links.forEach(function(link, i){
				if(link.href.match(/wiki/ig)){
					say_link = link;
					return;
				}
			});

			_this.speak_search(CHAN, 'GOOG', say_link, callback);
		});
	}
示例#3
0
      }, function (err, searchwords){
        if(err) console.error('Searchwords.create... Error while trying to create q!!'+err);
        else {
          google.resultsPerPage = 5;

          //get links from google
          google(data.q, function(err, next, links){
            if(!err) {
              res.json(links);
              //save query in local-database...
              //save linksBuilder in local-database..
              for(var i=0; i<links.length; i++){
                req.models.Links.one({ 
                  url: links[i].href 
                }, function(err, Links){ 
                  if(!err) console.log('Link fund! -->links['+i+'].href-->'+JSON.stringify(links[i]));
                  else {
                    req.models.Links.create({ 
                      createat: new Date(),
                      title: links[i].title,
                      url: links[i].href
                    }, function(err, items){
                      if(err) console.error(err);
                    });  
                  }
                });
              }
            }
          });
        }
      });
示例#4
0
	function searchAnime(query, cb) {
		google.resultsPerPage = 1;

		google('site:myanimelist.net/anime/ ' + query, function (err, next, links) {
			if (err) {
				cb(new Error('Attempt to google "' + query + '" failed with error: ' + (err.errno || err.message) + '.'), null);
				return;
			}

			if (!links.length) {
				cb(new Error('Sorry, no results for "' + query + '".'), null);
				return;
			}

			var link = links[0];
			var match = link.link.match(/^https?:\/\/myanimelist\.net\/anime\/(\d+)/);
			if (match) {
				cb(null, match[1]);
				// TODO: parse html or something similar to get data
			} else if (next) {
				next();
			} else {
				cb(new Error('Sorry, no results for "' + query + '".'), null);
			}
		});
	}
示例#5
0
addLyricsProvider("Uta-Net", function(artist, title, callback) {
  google('site:uta-net.com '+title+' '+artist, function(gErr, gRes) {
    if(gErr || !gRes.links[0]) {callback(false); return false;}
    request(gRes.links[0].link, function (error, response, html) {
      if (!error && response.statusCode == 200) {
        var ch$ = cheerio.load(html);
        var svgUrl = ch$('#ipad_kashi').find('img').attr('src');
        request('http://www.uta-net.com/'+svgUrl, function (error, response, svg) {
          if (!error && response.statusCode == 200) {
            var svg$ = cheerio.load(svg);
            var myLyrics = '';
            svg$('text').each(function (i, e) {
              myLyrics += e.children[0].data+"\n"
            });
            if(myLyrics) {
              callback(true, myLyrics.trim());
            }
            else {callback(false);}
          }
        });
      }
      else {
        callback(false);
      }
    });
  });
});
示例#6
0
var findSOQuestions = function(searchText, callback) {
	google.resultsPerPage = 5;	// limit this to five.
	Stats.DB().apiRequests++;
	
	// perform google search
	google(util.format('site:www.stackoverflow.com %s', searchText), (err, res) => {
		if (err) {
			return callback(err);
		}
		
		var soQuestions = [];
		
		res.links.forEach((link, index, array) => {
			soQuestions.push({'title': sanitizeTitle(link.title), 'url': link.href});
		});
		
		return callback(null, soQuestions);
		
		function sanitizeTitle (title) {
			const stackoverflowSuffix = " - Stack Overflow";
			
			try {
				return title.substring(0, (title.length - stackoverflowSuffix.length));
			} catch(er) {
				logger.warn('Failed to sanitize StackOverflow title: %s', er.message);
				return title;
			}
		}
	});
};
示例#7
0
router.get('/', function(req, res, next) {
	var request = require('request');
	var pos = require('pos');
	var words = new pos.Lexer().lex("The pos libary is working and it's f*****g awesome.");
	var taggedWords = new pos.Tagger().tag(words);
	var google = require('google')

	google.resultsPerPage = 25
	var nextCounter = 0
	
	google('node.js best practices', function (err, next, links){
	  if (err) console.error(err)

		console.log(err,links[0],next);

		//geodecoder: 
		var geocoderProvider = 'google';
		var httpAdapter = 'https';
		// optionnal
		
		var extra = {
		    apiKey: secrets.google.server, // for Mapquest, OpenCage, Google Premier
		    formatter: null         // 'gpx', 'string', ...
		};

		var geocoder = require('node-geocoder')(geocoderProvider, httpAdapter, extra);

		// Using callback
		geocoder.geocode('29 champs elysée paris', function(err, res) {
		    console.log(res);
		});

		res.render('index', { title: 'Express',links:links, taggedWords:taggedWords });
	});
});
示例#8
0
ion.on('connection', function(socket){
google('site:'+datos_post['pais']+'.linkedin.com '+datos_post['cadena'], function (err, next, links){
    if (err) console.error(err)

    links.forEach(function(link){
        setTimeout(function(){
            ex.getFromUrl(link.link,function(err,res){
                if(err){
                    console.log(err);
                }else{
                    if(res){
                        if (res['formattedName'] != ''){
                            ion.emit('message',{'message': jade.renderFile('tpl.jade',{
                                'formattedName':res.formattedName
                              , 'headline':res.headline
                              , 'location':res.location
                              , 'industry':res.industry
                              , 'numConnections':res.numConnections
                              , 'summary':res.summary
                              , 'pictureUrl':res.pictureUrl
                              , 'publicProfileUrl':res.publicProfileUrl
                            })});
                        }
                    }
                }
            });
            if(nextCounter<2){
                nextCounter += 1
                if (next) next()
            }                    
        },6000);
    });
});
});
示例#9
0
文件: General.js 项目: GrimIRC/grim
	this.googlesearch = function(command,from) {
		var google = require('google');
		
		// Max Number of results we will scrap from, this could be higher,
		// but we should only need 5 results and choose a random one to display
		google.resultsPerPage = 5;
		
		// Also to note, we could dynamically set this based on google.resultsPerPage
		// but for #smc, you wont need any higher
		var i = Math.floor(Math.random()*4);
			
		var url = 'http://www.google.com/search?hl=en&q='+command.args+'&ie=UTF-8&oe=UTF-8';
		//console.log("googleurl: ", url);
		if(command.command == "google") {
			google(command.args, function(err, next, links) {
		// NOTE: Some results -will- come up with a null/invalid link and so we count that as
		// no results to show, this isn't a flaw in our code, so much as the module is only a 
		// scrapper, not a api (api's are strongly not recommended due to auth and so many
		// queries per day or month (stuff can be open for abuse))
				if(!command.args) {
					chat.say("google_query_empty", []);
				} else {
					if(!links[i].link) {
						chat.say("google_no_valid_link", [command.args, url]);
					} else {
						chat.say("google", [command.args, links[i].link]);
					}
				}
			});
		} else if(command.command == "googleurl") {
			chat.say("googleurl", [command.args, url]);
		}
	}
示例#10
0
文件: index.js 项目: adarqui/darkness
(function() {
  "use strict";

  // maybe add optional results argument (argv[3])
  if (process.argv.length != 3) {
    console.error("usage: google-search <search string>");
    process.exit(1);
  }

  var Google = require('google');
  var max_results = 5;

  Google.resultsPerPage = max_results;
  var nextCounter = 0;

  Google(process.argv[2], function (err, next, links){

    if (err) {
      console.error(err);
      process.exit(1);
    }

    if (links === undefined) {
      console.error("No results.");
      process.exit(1);
    }

    for (var i = 0; i < (links.length > max_results ? max_results : links.length); ++i) {
      console.log(links[i].title + ' - ' + links[i].link);
    }

  });
}) ();
示例#11
0
var searchGoogle = function(bot, to, term) {

  // Set number of results per page (it might come from the first word of the term)
  google.resultsPerPage = 1;
  var firstTerm = term.split(' ')[0];
  if (isNumber(firstTerm)) {
    google.resultsPerPage = Math.min(parseInt(firstTerm), 5);
    term = term.split(' ').slice(1).join(' ');
  }
  
  util.log('Search Google for: ' + term + ' and get ' + google.resultsPerPage + ' results');
  
  google(term, function(err, next, links){
    if (err) {
      util.log(err);
      bot.say(to, 'Error fetching search results. Please try again later.');
      return;
    }

    if (links && links.length > 0)
    {
      // We want to show the lesser of what we have, or what we've specified as the limit
      for (var i = 0; i < Math.min(links.length, google.resultsPerPage); ++i) {
        var text = links[i].title;
        if (links[i].link != null) {
          text += ' - ' + links[i].link;
        }
        bot.say(to, text);
      }
    }
    else {
      bot.say(to, 'No Google results for search term: ' + term);
    }
  });
};
示例#12
0
  return new Promise((resolve, reject) => {
    try {
      google(query, (err, res) => {
        if (err) { reject(new Error(err.message)) }

        const items = []  // Object in Array

        if (res) {
          for (const item of res.links) {
            if (item.title && item.link && item.description) {
              if (!simple) {  // google
                items.push({ title: item.title, link: item.link, description: item.description })
              } else {  // gg
                items.push({ title: item.title, link: item.link })
              }
            }
          }
        } else {
          reject(new Error(speech.google.emptyResponse))
        }

        if (items.length >= 1) {
          resolve(items)
        } else {
          reject(new Error(speech.google.resultsBelow))
        }
      })
    } catch (e) {
      const errMessage = e.code + '\n\n' + e.stack
      console.error(errMessage)
      reject(new Error(speech.google.emptyResponse))
    }
  })
示例#13
0
function searchGoogle(text, lang, callback) {
    google.resultsPerPage = 40;

    var site;
    if(lang) {
        site = 'site:stackoverflow.com ' + lang;
    }
    else {
        site = 'site:unix.stackexchange.com';
    }
    var searchQuery = site + ' ' + text;

    google(searchQuery, function (err, next, links){
        if(err) {
            return googleError(err, links);
        }

        links = links.filter(function(link) {
            return link.title !== '';
        })
        .filter(utils.isValidGoogleLink);

        var strippedTitles = links.map(function(link) {
            var title = utils.stripStackOverflow(link.title);
            return title;
        });

        callback(links, strippedTitles);

    })
}
示例#14
0
文件: test.js 项目: jailbot/dnbot
function googleSearch(query){
  var body = "";
  google.resultsPerPage = 1;
  for(var i=1; i<query.length; i++){
    body += query[i] + " ";
  }
  google(body, function(err, next, links){
    console.log(links[0]);
  });
}
示例#15
0
	google(pageTitle, function(err, origRes){
		var origbody = origRes.body
		hitCounts.hitCount = Number(origbody.match(/(\>About )([0-9|\,]+)( results\<)/)[2].split(',').join(''));
		google(fakePageTitle, function(err, fakeRes){
			console.log('error ' + err);
			hitCounts.fakehitCount = Number(fakeRes.body.match(/(\>About )([0-9|\,]+)( results\<)/)[2].split(',').join(''));
			chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
	  			chrome.tabs.sendMessage(tabs[0].id, hitCounts);
			});
		})
	})
示例#16
0
文件: app.js 项目: ohmfox/dnbot
/* ------------------ */
/* Do a google search */
/* ------------------ */
function googleSearch(query){
  var body = "";
  google.resultsPerPage = 1;
  for(var i=1; i<query.length; i++){
    body += query[i] + " ";
  }
  google(body, function(err, next, links){
    if (err) throw err;
    bot.say(config.channels[0], links[0].title + " - " + links[0].href);
  });
}
示例#17
0
文件: wikipedia.js 项目: ithil/rowboe
 function wikiGoogle(opt, callback) {
     Google("site:en.wikipedia.org "+opt.cmd.join(' '), function (err, next, links) {
         if(!err && links[0]) {
             var link = links[0].link;
             var match = pat.exec(link);
             if(match[2]) {
                 opt.query = match[2];
                 wikipedia(opt, function (abstr) {callback(opt.to, abstr);});
             }
         }
     });
 }
示例#18
0
文件: google.js 项目: ithil/rowboe
 function google(opt, callback) {
     var all = opt.all || false;
     Google(opt.cmd.join(' '), function (err, next, links) {
     for(var i=0; i < (all?10:1); i++) {
       if(links[i]) {
           if(links[i].link) {
               callback(opt.to, links[i].link+b(links[i].title));
           }
       }
     }
     });
 }
示例#19
0
    Util.getRelatedWord = function(word, cb) {
        // cb(null, origin_value, resultList);
        var origin_value = word;
        google(word, function(err, next, links) {
            if (origin_value == Util.latest_search_input || !Util.latest_search_input) {
                if (err)
                    cb(err);
                else {
                    var freq_hash_map = {};

                    links.forEach(function(l) {
                        recordFreq(freq_hash_map, l.title.removeStopWordsAndGetArray());
                        recordFreq(freq_hash_map, l.description.removeStopWordsAndGetArray());
                    });
                    var num = 10,
                        resultList;
                    resultList = sortObjectByValue(freq_hash_map).slice(0,10).map(function(x){
                        return x[0];
                    });

                    cb(null, origin_value, resultList);
                    // Util.MultiRequest(links.map(function(x) {
                    //     return x.href;
                    // }).filter(function(x) {
                    //     return x;
                    // }), function(err, res) {
                    //     if (err) {
                    //         throw err;
                    //     } else {
                    //         if (origin_value == Util.latest_search_input || !Util.latest_search_input) {
                    //             res.forEach(function(r) {
                    //                 var body = r[1];
                    //                 debugger;
                    //                 excerptHtml(body);
                    //                 var $ = cheerio.load(body);

                    //             });

                    //         } else {
                    //             console.log('hit');
                    //         }
                    //     }
                    // });
                    //use title, description
                }
            } else {
                console.log('hit');
            }
        });

    };
示例#20
0
global.Google = function (query, callback){
	var results = new Array();
	google(query, function(err, next, links){
	  if (err) callback(err);
	  for (var i = 0; i < links.length; ++i) {
		  var result = new Object();
			result.title = links[i].title;
			result.link = links[i].link;
			result.description = links[i].description;	
			results[i] = result;
	  }
	  callback(results)
	});
}
示例#21
0
文件: messages.js 项目: Krewe/snarl
  , google: function(data) {
      var self = this;
      if (typeof(data.params) != 'undefined') {
        google(data.params, function(err, next, links) {
          if (err) { console.log(err); }

          if (typeof(links[0]) != 'undefined') {
            self.chat(links[0].title + ': ' + links[0].link);
          }

        });
      } else {
        self.chat('No query provided.');
      }
    }
示例#22
0
 execute(msg, args) {
   super.execute.apply(this, arguments);
   if (!this.validate(args, 1)) return;
   
   let bot = msg.client,
       results = [],
       link = {};
   
   bot.g = bot.g || {};
   
   if (args.length === 1 && args[0] === "next") {
     results = bot.g[msg.channel];
     
     while (!link.href && results.links.length) {
       link = results.links.shift();
     }
     
     if (!link.href) {
       this.sendMessage("I'm out of results");
       return;
     }
     
     this.sendMessage(link.href);
     link = {};
     return;
   }
   
   google.resultsPerPage = 10;
   google(args.join(' '), (err, res) => {
     if (err) { return this.log("Error", err); }
     
     if (!res.links.length) {
       return this.sendMessage("I didn't get any results");
     }
     
     bot.g[msg.channel] = res;
     
     while (!link.href && res.links.length) {
       link = res.links.shift();
     }
     
     results = res.links;
     
     this.sendMessage(link.href);
     
     link = {};
   });
 }
示例#23
0
const googleSearch = (query, callback) => {
  google(query, (err, res) => {
    if (err) {
      log.debug('Something went wrong?');
    }
    const links = res.links;

    if (links && links.length) {
      const filtered = links.filter((link) => link.href !== null);
      const link = filtered[0];
      if (link.href) {
        callback(link.href);
      }
    }
  });
};
示例#24
0
function getPortal(name, done){
  google.resultsPerPage = 10;
  var nextCounter = 0;

  google(name + ' data portal', function(err, next, links){
    if (err) console.error(err);
    for (var i = 0; i < links.length; ++i) {
      console.log(links[i].title + ' - ' + links[i].link); //link.href is an alias for link.link
      console.log(links[i].description + "\n");
      portals += '\n"'+name+'",'
      portals += '"'+links[i].link+'",'
      portals += '"'+links[i].title+'",'
      portals += '"'+links[i].description.split('"').join('')+'"'
    }
    done()
  });
}
示例#25
0
chrome.runtime.onMessage.addListener(function(pageTitle, sender, responseFunc){
	var fakePageTitle = pageTitle + ' fake story';
	var hitCounts = {}
	hitCounts.fakepagetitle = fakePageTitle;
	hitCounts.pagetitle = pageTitle;
	google(pageTitle, function(err, origRes){
		var origbody = origRes.body
		hitCounts.hitCount = Number(origbody.match(/(\>About )([0-9|\,]+)( results\<)/)[2].split(',').join(''));
		google(fakePageTitle, function(err, fakeRes){
			console.log('error ' + err);
			hitCounts.fakehitCount = Number(fakeRes.body.match(/(\>About )([0-9|\,]+)( results\<)/)[2].split(',').join(''));
			chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
	  			chrome.tabs.sendMessage(tabs[0].id, hitCounts);
			});
		})
	})
})
            handler: function (request, reply) {
                const siteSearch = 'site:youtube.com/watch ';
                const videoName = request.params.videoName;
                var resultList = [];
                google(siteSearch + videoName, function (err, res){
                    if(err){
                        return reply(err);
                    }else{
                        res.links.forEach((data)=>{
                            console.log(data);
                            resultList.push(data);
                        });

                        return reply(resultList);
                    }
                })

            }
GoogleTrigger.prototype._respond = function(toId, message) {
	var query = this._stripCommand(message);
	if (query) {
		var that = this;
		google(query, function(err, next, links){
			if (err || !links || links.length < 1) {
				winston.error("Error querying google or no links found: " + err);
				that._sendMessageAfterDelay(toId, "¯\\_(ツ)_/¯");
			}
			else {
				that._sendMessageAfterDelay(toId, links[0].title + ": " + links[0].link);
			}
		});

		return true;
	}
	return false;
}
示例#28
0
文件: google.js 项目: Ditti4/GLaDOS
 scriptLoader.on('command', ['g', 'google'], function (event) {
     if (event.params.length > 0) {
         google(event.text, function (error, next, links) {
             if (!error) {
                 if (links.length > 0) {
                     event.channel.reply(event.user, links[0].title + ' (' + links[0].link + ')');
                 } else {
                     event.channel.reply(event.user, 'Your search - ' + event.text + ' - did not match any documents.');
                 }
             } else {
                 event.channel.reply(event.user, 'Gratz. You broke it. (' + error + ') ');
                 scriptLoader.debug('%s', error);
             }
         });
     } else {
         event.user.notice('Use: !google <query>');
     }
 });
示例#29
0
addLyricsProvider("Songtexte.com", function(artist, title, callback) {
  google('site:songtexte.com '+title+' '+artist, function(gErr, gRes) {
    if(gErr || !gRes.links[0]) {callback(false); return false;}
    request(gRes.links[0].link, function (error, response, html) {
      if (!error && response.statusCode == 200) {
        var ch$ = cheerio.load(html);
        // Extracting the lyrics
        var myLyrics = ch$('#lyrics').text().trim()
        if(myLyrics && !(myLyrics.includes('Leider kein Songtext vorhanden.'))) { // Dirty but necessary
          callback(true, myLyrics.trim());
        }
        else {callback(false);}
      }
      else {
        callback(false);
      }
    });
  });
});
示例#30
0
addLyricsProvider("AZLyrics", function(artist, title, callback) {
  google('site:azlyrics.com '+title+' '+artist, function(gErr, gRes) {
    if(gErr || !gRes.links[0]) {callback(false); return false;}
    request(gRes.links[0].link, function (error, response, html) {
      if (!error && response.statusCode == 200) {
        var ch$ = cheerio.load(html);
        // Extracting the lyrics
        var myLyrics = ch$(ch$('div.ringtone').nextAll('div')[0]).text().trim()
        if(myLyrics) {
          callback(true, myLyrics.trim());
        }
        else {callback(false);}
      }
      else {
        callback(false);
      }
    });
  });
});