Created
June 12, 2009 13:17
-
-
Save DRMacIver/128628 to your computer and use it in GitHub Desktop.
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 "rubygems" | |
require "json" | |
require "httparty" | |
# Ruby script for fetching the "liked" history of a reddit user as json | |
module Reddit | |
include HTTParty | |
base_uri "http://reddit.com" | |
format :json | |
def self.liked(user) | |
results = [] | |
after=nil | |
new_results = nil | |
while !(new_results = get("/user/#{user}/liked/.json", :query => {"after" => after})["data"]["children"]).empty? | |
results += new_results | |
last = new_results[-1] | |
after = last["kind"] + "_" + last["data"]["id"] | |
end | |
results | |
end | |
end | |
if $0 == __FILE__ | |
puts Reddit.liked(ARGV[0].strip).to_json | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment