다음은 migration에 사용한 코드입니다.
#! /usr/bin/ruby
require ‘xmlrpc/client’
require ‘net/http’
require ‘uri’
require ‘pp’
MT_XMLRPC_URL=’http://YOUR_HOST/mt/mt-xmlrpc.cgi’)
MT_BLOG_ID=’YOUR_BLOG_ID’
MT_ID=’YOUR_ID’
MT_PW=’YOUR_PW’
NUM_POSTS=1000
DELICIOUS_ID=’YOUR_DELICIOUS_ID’
DELICIOUS_PW=’YOUR_DELICIOUS_PW’
# get all posts from MT
server = XMLRPC::Client.new2(MT_XMLRPC_URL)
result = server.call("metaWeblog.getRecentPosts", MT_BLOG_ID, MT_ID, MT_PW, NUM_POSTS)
result.each do |post|
description = post["title"]
url = post["mt_excerpt"]
extended = post["description"]
dt = post["dateCreated"].to_time.iso8601
print description + "\n"
print url + "\n"
print extended + "\n"
print dt + "\n"
# post it to delicious
response = Net::HTTP.get_response(URI.parse(‘http://del.icio.us/api/posts/add?’ + ‘url=’ + URI.escape(url) + ‘&description=’ + URI.escape(description) + ‘&extended=’ + URI.escape(extended) + ‘&dt’ + URI.escape(dt)))
Net::HTTP.start(‘del.icio.us’) {|http|
req = Net::HTTP::Get.new(‘/api/posts/add?’ + ‘url=’ + URI.escape(url) + ‘&description=’ + URI.escape(description) + ‘&extended=’ + URI.escape(extended) + ‘&dt=’ + URI.escape(dt))
req.basic_auth (DELICIOUS_ID, DELICIOUS_PW)
response = http.request(req)
print response.body
}
# throttling
sleep(1)
end