Created
September 19, 2012 05:21
-
-
Save scpike/3747827 to your computer and use it in GitHub Desktop.
Grab a list of all the foursquare venues
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
# ruby grab_venues.rb will print a csv of all the foursquare venue types | |
# flattens the nested hash of venues | |
url = "https://api.foursquare.com/v2/venues/categories?oauth_token=your_token&v=20120828" | |
require 'json' | |
# hashes are nested, containing arrays of hashes of category information | |
def print_hash(hash) | |
# We've found a category | |
if hash['id'] and hash['name'] | |
puts "#{hash['id']},#{hash['name']}" | |
end | |
# We've found an array of hashes of categories (that might contain more arrays!) | |
if hash["categories"] | |
hash["categories"].each do |h| | |
print_hash(h) | |
end | |
end | |
end | |
ret = `curl #{url}` | |
json_response = JSON.parse(ret) | |
puts json_response["response"]["categories"].first | |
json_response["response"]["categories"].each do |c| | |
print_hash(c) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment