Skip to content

Instantly share code, notes, and snippets.

@wilsaj
Created May 7, 2015 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilsaj/40d82c925ff92828e520 to your computer and use it in GitHub Desktop.
Save wilsaj/40d82c925ff92828e520 to your computer and use it in GitHub Desktop.
yelp reviews to csv
'use strict';
var _ = require('lodash');
var csv = require('csv-write-stream');
var fs = require('fs');
var mapquest = require('mapquest');
var nconf = require('nconf');
nconf.file({file: 'credentials.json'});
var yelp = require("yelp").createClient({
consumer_key: nconf.get("consumer_key"),
consumer_secret: nconf.get("consumer_secret"),
token: nconf.get("token"),
token_secret: nconf.get("token_secret")
});
var geocoder = require('node-geocoder').getGeocoder(
'mapquest', 'http', {apiKey: nconf.get('mapquest_api_key')}
);
var writer = csv();
writer.pipe(fs.createWriteStream('yelp-reviews.csv'));
// See http://www.yelp.com/developers/documentation/v2/search_api
_.each([0, 1], function(offset) {
var limit = 20;
var radius = 5000;
yelp.search({term: "food", ll: "30.387029,-97.726586", sort: 2, radius: radius, limit: limit, offset: limit * offset}, function(error, data) {
console.log(error);
console.log(data);
_.each(data.businesses, function(business) {
var location = business.location.address.join(" ") + " " + business.location.city + ", " + business.location.state_code + " " + business.location.postal_code;
geocoder.geocode(location, function(error, response) {
var obj = {
name: business.name,
rating: business.rating,
review_count: business.review_count,
latitude: response[0].latitude,
longitude: response[0].longitude
};
writer.write(obj);
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment