Created
October 2, 2013 14:04
-
-
Save davidbella/6794313 to your computer and use it in GitHub Desktop.
Ruby: Reddit API and HTML output
This file contains hidden or 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 'rest_client' | |
reddit_hash = JSON.parse(RestClient.get('http://reddit.com/.json')) | |
reddit_hash["data"]["children"].select! { |story| story["data"]["subreddit"] != "gaming" } | |
puts "<html>" | |
puts "<head>" | |
puts "</head>" | |
puts "<body>" | |
puts "<ul>" | |
reddit_hash["data"]["children"].each do |story| | |
puts "<li>" | |
puts "<a href=\"#{story["data"]["url"]}\">" | |
puts "<h1>#{story["data"]["title"]}</h1>" | |
puts "<img src=\"#{story["data"]["thumbnail"]}\" />" | |
puts "<h4>Upvotes:</p>" | |
puts "<p>#{story["data"]["ups"]}</h4>" | |
puts "<p>Downvotes:</p>" | |
puts "<h4>#{story["data"]["downs"]}</h4>" | |
puts "</a>" | |
puts "</li>" | |
end | |
puts "</ul>" | |
puts "</body>" | |
puts "</html>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment