링크 블로그에서 del.icio.us로의 이전

| | Comments (0) | TrackBacks (0)

최근에는 del.icio.us를 쓰고 있는데, 기존에 쓰던 링크 블로그 데이터만 덩그러니 남겨두기가 뭐해서, 간단한 ruby 스크립트를 짜서 데이터를 이전했습니다. 아시는 분은 아시다시피, MovableType은 Blogger APIMetaWeb API 뿐만 아니라, 최근에는 Atom Publishing Protocol까지 지원하고 있고, del.icio.us는 Web 2.0 계의 대표적인 서비스답게 del.icio.us API를 제공하고 있습니다. Blogger API와 MetaWeb API들은 MovableTypeWriter를 개발하면서 사용했었기 때문에 익숙했지만, del.icio.us의 API는 처음 보았습니다. XMLRPC나 REST 계열의 API만 보다가 HTTP GET을 사용한 API를 보니 좀 특이하더군요. (개인적으로는 그리 마음에 들지 않습니다.)

결과를 보시고 싶은 분은 제 del.icio.us 페이지를 한번 방문해보시죠. 반나절 정도의 노력을 들여서 완전히 다른 종류의 서비스 사이에서 데이터 이전이 가능하다는 것, 멋지지 않습니까?

다음은 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

0 TrackBacks

Listed below are links to blogs that reference this entry: 링크 블로그에서 del.icio.us로의 이전.

TrackBack URL for this entry: http://lastmind.net/mt/mt-tb.cgi/274

Leave a comment

About this Entry

This page contains a single entry by Joseph Jang published on January 2, 2006 9:05 PM.

Eve Online - Captain's Log: Day 1 was the previous entry in this blog.

백세주 CF의 옥지영 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.21-en