Skip to content

Instantly share code, notes, and snippets.

@avegancafe
Created April 23, 2015 05:12
Show Gist options
  • Save avegancafe/008836386b6d0819f083 to your computer and use it in GitHub Desktop.
Save avegancafe/008836386b6d0819f083 to your computer and use it in GitHub Desktop.
var keys = require('./keys'),
yelp = require('yelp').createClient( keys );
var until = function(n, cb){
return function(){ (--n) || cb(); };
};
module.exports = function (search, zip, cb) {
function search(offset, cb, arr){
yelp.search({ term: search, location: zip, offset: offset }, function (err, data) {
if( err ){ throw err; }
if( arr ){ [].splice.apply(arr, [0,0].concat(data.businesses)); }
cb(offset, data);
});
}
search(0, function (offset, data){
var done = until(Math.ceil((data.total-20)/20), function(){
console.log(data.total, data.businesses.length);
});
for( var i = 20; (i < data.total && i < 1000); i += 20 ){
search(i, done, data.businesses);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment