Skip to content

Instantly share code, notes, and snippets.

@narkisr
Created April 10, 2010 20:31
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 narkisr/362277 to your computer and use it in GitHub Desktop.
Save narkisr/362277 to your computer and use it in GitHub Desktop.
require 'yaml'
require 'ostruct'
require 'xmlrpc/client'
require "cgi"
key = "34af1ea48bef1d5ed090"
server = XMLRPC::Client.new( "snipplr.com", "/xml-rpc.php")
server.call("user.checkkey", key)
hashes = server.call("snippet.list",key)
subset = hashes.select {|e| e['updated']['datetime'].to_date > Date.strptime("11/12/2009", "%d/%m/%Y")}.sort{ |a , b| b['updated']['datetime'].to_date <=> a['updated']['datetime'].to_date}
ids = subset.map {|it| it['id']}
ids.each do |id|
begin
snippet=server.call("snippet.get", id)
snippet['source'] = CGI::unescapeHTML(snippet['source'])
output=File.new("#{id}.txt",'w')
output.puts(YAML.dump(snippet.to_yaml))
output.close
rescue => e
failed = hashes.find {|it| it['id']== id}
puts "The #{failed['title']} #{failed['private']} seems to be private"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment