Created
February 8, 2014 19:11
-
-
Save johnrees/8888574 to your computer and use it in GitHub Desktop.
This file contains 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
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