Skip to content

Instantly share code, notes, and snippets.

@DRMacIver
Created June 12, 2009 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DRMacIver/128628 to your computer and use it in GitHub Desktop.
Save DRMacIver/128628 to your computer and use it in GitHub Desktop.
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