Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Export del.icio.us links to MT Import Format (See related posts)

A friend of mine needed his del.icio.us links in MT Import format for some reason. This solved that problem.

require 'rexml/document'
require 'net/https'
require 'rubygems'

# change credentials!
user = 'username'
pass = 'password'

# User-Agent: required for del.icio.us api
agent = 'delicious-mt'
xml = ''

http = Net::HTTP.new('api.del.icio.us', 443)
http.use_ssl = true
http.start do |http|
  request = Net::HTTP::Get.new('/v1/posts/all', {'User-Agent' => agent})
  request.basic_auth(user, pass)
  response = http.request(request)
  response.value
  xml = response.body
end
 
REXML::Document.new(xml).elements.each('posts/post') do |el|
  puts "TITLE: #{el.attributes['description']}"
  puts "AUTHOR: Author Name"
  puts "DATE: #{DateTime.parse(el.attributes['time']).strftime("%m/%d/%Y %H:%M:%S")}"
  puts "-----"
  puts "BODY:"
  puts el.attributes['extended']
  puts "-----"
  puts "EXCERPT:"
  puts el.attributes['href']
  puts "KEYWORDS:"
  puts el.attributes['tag']
  puts "-----"
  puts "--------"
end

You need to create an account or log in to post comments to this site.


Click here to browse all 5147 code snippets

Related Posts