Skip to content

Instantly share code, notes, and snippets.

@willbailey
Created December 5, 2008 14:31
Show Gist options
  • Save willbailey/32344 to your computer and use it in GitHub Desktop.
Save willbailey/32344 to your computer and use it in GitHub Desktop.
audit the privacy settings on documents uploaded to the scribd api
# This script will verify the privacy settings on documents you have loaded
# to the scribd api.
require 'rubygems'
require 'hpricot'
require 'open-uri'
def get_docs(api_uri, limit, offset)
api_uri += "&limit=#{limit}&offset=#{offset}"
puts "request api with limit:#{limit} and offset:#{offset}"
puts api_uri
Hpricot(open(api_uri))
end
def audit_privacy_settings(api_key)
limit = 1000
offset = 0
public_docs = []
count = 0
api_uri = "http://api.scribd.com/api?api_key=#{api_key}&method=docs.getList&use_api_account=1"
results = (get_docs(api_uri, limit, offset)/"result")
while results.size > 0
results.each do |r|
unless (r/"secret_password").size > 0
public_docs.push(r)
puts "public document found: total is #{public_docs.size}"
else
puts((r/"doc_id").inner_html + " is private")
end
count += 1
end
offset +=1000
results = (get_docs(api_uri, limit, offset)/"result")
end
puts "*"*30
puts "PUBLIC DOCUMENTS"
puts "*"*30
public_docs.each do |d|
puts((d/"doc_id").inner_html + " is a public document!")
end
puts "*"*30
puts "SUMMARY"
puts "*"*30
puts "total documents: #{count}; public_documents: #{public_docs.size}; private documents : #{count - public_docs.size}"
end
if __FILE__ == $0
if ARGV[0]
audit_privacy_settings(ARGV[0])
else
puts "usage: please provide your api key"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment