Skip to content

Instantly share code, notes, and snippets.

@TrevMcKendrick
Created October 11, 2013 15:21
Show Gist options
  • Save TrevMcKendrick/6936571 to your computer and use it in GitHub Desktop.
Save TrevMcKendrick/6936571 to your computer and use it in GitHub Desktop.
require 'json'
require 'rest_client'
reddit_url = "http://www.reddit.com/"
reddit_hash = JSON.parse(RestClient.get('http://www.reddit.com/.json'))
#puts reddit_hash["data"]["children"][1]
#reddit_hash["data"].each {|k,v| puts k}
filtered_posts = []
reddit_hash["data"]["children"].each_with_index do |post,index|
if reddit_hash["data"]["children"][index]["data"]["over_18"] == false
filtered_posts << reddit_hash["data"]["children"][index]
end
end
#puts filtered_posts[0]
puts "<html>"
puts "<head>"
#puts "<link rel=\"stylesheet\" type=\"text/css\" href=\"http://www.redditstatic.com/reddit.TcCdE3UU-bY.css"
puts "</head>"
puts "<body>"
puts "<ul>"
filtered_posts.each_with_index do |post,index|
puts "<li>"
puts "<a href=#{reddit_hash["data"]["children"][index]["data"]["url"]}"
puts "<h1>" + filtered_posts[index]["data"]["title"] + "</h1>"
puts "<img src= #{filtered_posts[index]["data"]["thumbnail"]}> </img>"
puts "<h4>Upvotes:</h4>"
puts "<p>#{filtered_posts[index]["data"]["ups"]}</p>"
puts "<p>Downvotes:</p>"
puts "<p>#{filtered_posts[index]["data"]["downs"]}"
puts "</li>"
puts "</a>"
puts "</li>"
end
puts "</ul>"
puts "</body>"
puts "</html>"
# key_values for data
# Proof: this is linked from http://www.kickstarter.com/projects/failbetter/sunless-sea/posts . And at 11:00 today BST, the Fallen London Twitter account (@echobazaar) will post about a dark bird.
# Key:likes Value:
# Key:secure_media Value:
# Key:saved Value:false
# Key:id Value:1nknpk
# Key:secure_media_embed Value:{}
# Key:clicked Value:false
# Key:stickied Value:false
# Key:author Value:lessofthat
# Key:media Value:
# Key:score Value:128
# Key:approved_by Value:
# Key:over_18 Value:false
# Key:hidden Value:false
# Key:thumbnail Value:self
# Key:subreddit_id Value:t5_2qzb6
# Key:edited Value:false
# Key:link_flair_css_class Value:gaming
# Key:author_flair_css_class Value:
# Key:downs Value:80
# Key:is_self Value:true
# Key:permalink Value:/r/IAmA/comments/1nknpk/im_alexis_kennedy_founder_chief_narrative_officer/
# Key:name Value:t3_1nknpk
# Key:created Value:1380735940.0
# Key:url Value:http://www.reddit.com/r/IAmA/comments/1nknpk/im_alexis_kennedy_founder_chief_narrative_officer/
# Key:author_flair_text Value:
# Key:title Value:I'm Alexis Kennedy, founder / chief narrative officer of Failbetter Games, who make the Fallen London online game and are now building the Sunless Sea spinoff. Other Failbetters will be here too. Ask us questions!
# Key:created_utc Value:1380707140.0
# Key:link_flair_text Value:
# Key:ups Value:208
# Key:num_comments Value:137
# Key:num_reports Value:
# Key:distinguished Value:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment