Skip to content

Instantly share code, notes, and snippets.

@johnrees
Created February 8, 2014 19:11
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 johnrees/8888574 to your computer and use it in GitHub Desktop.
Save johnrees/8888574 to your computer and use it in GitHub Desktop.
require 'json'
require 'open-uri'
raw_json = open('http://api.smartcitizen.me/v0.0.1/ba997ab4b0e21eda08b3da4a7b60a628/646/posts.json?from_date=2014-02-06&to_date=2014-02-08').read
json = JSON.parse(raw_json)
File.open('posts.csv', 'w') do |file|
# write first line
file.puts json["device"]["posts"][0].keys.join(',')
# loop through posts, write each line of data
json["device"]["posts"].each do |post|
file.puts post.values.join(',')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment