I’ve just been caught out by the del.icio.us api change (they’ve just switched off the old api). This broke the backup script I use. It’s a nice script, it downloads each days bookmarks into a sqlite database, ready for reuse.
Anyway, this is the patch I wrote to make it use the new api (over SSL) instead. BTW, top marks to the del.icio.us people for using basic auth instead of coming up with their own scheme. Basic auth + SSL is a really nice, simple way of doing things.
--- /home/dom/delicious-backup.rb.orig Fri Aug 11 09:00:39 2006 +++ /home/dom/bin/delicious-backup.rb Fri Aug 11 09:09:19 2006 @@ -26,11 +32,29 @@ 'values (?, ?, ?, ?, ?);' insert_tag = 'insert into tags (hash, tag) values (?, ?);' -xml = Net::HTTP.start('del.icio.us') { |http| - req = Net::HTTP::Get.new('/api/posts/all', {'User-Agent' => agent}) +# https://api.del.icio.us/v1/posts/get +require 'net/https' +http = Net::HTTP.new('api.del.icio.us', 443) +http.use_ssl = true +http.verify_mode = OpenSSL::SSL::VERIFY_NONE +xml = http.start { |conn| + req = Net::HTTP::Get.new('/v1/posts/all', {'User-Agent' => agent}) req.basic_auth(user, pass) - http.request(req).body + resp = conn.request(req) + raise resp.inspect unless resp.kind_of? Net::HTTPSuccess + resp.body } + +Dir.chdir(ARGV[1] || ENV['HOME'] + '/libdata/del.icio.us') + +# Clean anything over 30 days. +thirty_days_ago = Time.now - (30 *(24*60*60)) +Dir["*.db"].each do |name| + f = File.new(name) + if f.mtime < thirty_days_ago + File.unlink(name) + end +end db_name = ARGV[0] || Time.now.strftime("%Y-%m-%d.db") SQLite3::Database.open(db_name).transaction { |db|
That’s also got my backup expiry bits in, which is handy, but could probably be done better. BTW, that ruby idiom of indexing the Dir class to run a glob is freakish.