Skip to content

Instantly share code, notes, and snippets.

@cmlawson
Created January 28, 2013 09:51
Show Gist options
  • Save cmlawson/4654306 to your computer and use it in GitHub Desktop.
Save cmlawson/4654306 to your computer and use it in GitHub Desktop.
require 'google_places'
require "CSV"
API_KEY = "AIzaSyBTtzGadlCexbNTKtUxQWS65SRiewtpkgU"
@client = GooglePlaces::Client.new(API_KEY)
searchRadius = 50
lat = 47.61001843
long = -122.3426235
reviewsPerLocation = 5
numberOfLocations = 5
reviewsPerLocCount = 0
numberOfLocCount = 0
results= @client.spots(lat, long, :name => 'Starbucks', :radius=>searchRadius)
spot = @client.spot(results[0].reference)
reviewArray = [:text => "text", :rating => "rating", :ratingType=>"Rating Type",:author_url => "Author URL",:time=>"Time"]
CSV.open("google_places_reviews.csv", "w")
spot.reviews.each do |review|
reviewArray << {:text=>review.text,:rating =>review.rating,:ratingType=>review.type,:author_url =>review.author_url,:time=>review.time}
break if reviewsPerLocCount > reviewsPerLocation
CSV.open("google_places_reviews.csv", "a+") do |csv|
csv << reviewArray[reviewsPerLocCount].values
end
reviewsPerLocCount +=1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment