Skip to content

Instantly share code, notes, and snippets.

@gregeng
Last active December 25, 2015 13:09
Show Gist options
  • Save gregeng/6981556 to your computer and use it in GitHub Desktop.
Save gregeng/6981556 to your computer and use it in GitHub Desktop.
Safe For Work Reddit
require 'json'
require 'rest_client'
reddit_hash = JSON.parse(RestClient.get('http://reddit.com/.json'))
html_reddit = "<html><head></head><body><ul>"
reddit_hash["data"]["children"].each do |post|
next if post["data"]["over_18"] == true
html_reddit << "<li>"
html_reddit << "<a href=\"#{post["data"]["url"]}\">"
html_reddit << "<h1>#{post["data"]["title"]}</h1>"
html_reddit << "<img src=\"#{post["data"]["thumbnail"]}\"/>"
html_reddit << "<h4>Upvotes:</p>"
html_reddit << "<p>#{post["data"]["ups"]}</h4>"
html_reddit << "<p>Downvotes:</p>"
html_reddit << "<h4>#{post["data"]["downs"]}</h4>"
# html_reddit << "<p>NSFW: #{post["data"]["over_18"]}</p>"
html_reddit << "</a></li>"
end
html_reddit << "</ul></body></html>"
File.open("reddit_frontpage.html", 'w') { |file| file.write("#{html_reddit}") }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment