Skip to content

Instantly share code, notes, and snippets.

@cbfrance
Created May 27, 2010 02:19
Show Gist options
  • Save cbfrance/415356 to your computer and use it in GitHub Desktop.
Save cbfrance/415356 to your computer and use it in GitHub Desktop.
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