Created
February 28, 2014 04:47
-
-
Save gniemira/9265428 to your computer and use it in GitHub Desktop.
Grab the last 10 pages of journals from the Kiva api and spit out an HTML page with them.
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 'httparty' | |
file = File.new("journals " + Time.now.to_s + ".html", "w") | |
file.puts '<!DOCTYPE html><html><head><title>Journals</title><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script><link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"><script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script></head><body><div class="container">' | |
puts "making html file" | |
url = "http://api.kivaws.org/v1/journal_entries/search.json?newest&page=" | |
page = 0 | |
10.times do | |
page += 1 | |
journal_entries = HTTParty.get(url + page.to_s)["journal_entries"] | |
journal_entries.each do |journal| | |
puts "getting journal " + journal['id'].to_s | |
journal_entry = "<div>" | |
journal_entry += "<a href='http://www.kiva.org/updates/loan/#{journal['id'].to_s}' target='_blank'>ID #{journal['id'].to_s}</a>" | |
journal_entry += "<h4>#{journal["subject"]}</h4>" | |
journal_entry += "<p>#{journal["body"]}</p>" | |
journal_entry += "<p>Published #{journal["date"].to_s}</p>" | |
journal_entry += "<p>Reco count #{journal["recommendation_count"].to_s} </p>" | |
journal_entry += "<p>Comment count #{journal["comment_count"].to_s}</p>" | |
journal_entry += "<p>Author: #{journal["author"]}</p>" | |
journal_entry += "</div>" | |
file.puts journal_entry | |
end | |
sleep 10 | |
end | |
file.puts "</div></body></html>" | |
puts "saving file" | |
file.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment