Created
May 7, 2015 18:16
-
-
Save wilsaj/40d82c925ff92828e520 to your computer and use it in GitHub Desktop.
yelp reviews to csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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