Created
May 27, 2010 02:19
-
-
Save cbfrance/415356 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
if File.exist?('haiti.json.txt') | |
# parse the file | |
p "reading from the existing file ...." | |
jsonfile= File.open("haiti.json.txt", "r") | |
results= jsonfile.read | |
parsed_results= Crack::JSON.parse(results) | |
@incidents = parsed_results['payload']['incidents'] | |
pdf.bounding_box([x_pos, y_pos], :width => 300, :height => 400) do | |
@incidents.each do |i| | |
pdf.text i['incident']['incidentdescription'] | |
pdf.start_new_page | |
end | |
end | |
jsonfile.close | |
pdf.render_file("book.pdf") | |
`open book.pdf` | |
else | |
# write the file | |
p "reading directly from instance API ..." | |
response= HTTParty.get("http://haiti.ushahidi.com/api?task=incidents&by=all") | |
jsonfile= File.new("haiti.json.txt", "w") | |
data = response.body | |
puts data | |
jsonfile.write(data) | |
jsonfile.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment